在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常
错误:在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。 只有将调试器附加到该进程才会引发此异常在用c#编程时遇到这个问题,这是个多线程的下载程序,在调用保存对话框的时候发生,我的Main()函数有[STATThread]标记的,请问哪位能帮帮忙!!! --------------------编程问答-------------------- 我也遇到这样的问题,LZ是否已经解决? share下 --------------------编程问答-------------------- 帮顶,我也遇到这问题了 --------------------编程问答-------------------- Thread app = new Thread(new ParameterizedThreadStart(ShowWindow));
app.ApartmentState = ApartmentState.STA; --------------------编程问答-------------------- Thread app = new Thread(new ParameterizedThreadStart(ShowWindow));
app.ApartmentState = ApartmentState.STA;
也可以
Thread newThread = new Thread(new ThreadStart(ThreadMethod));
newThread.SetApartmentState(ApartmentState.MTA);
详细请参照
http://msdn.microsoft.com/zh-cn/architecture/system.threading.apartmentstate.aspx
--------------------编程问答-------------------- 在主函数前面加上[STAThread]即可
如:.................................
...............................
[STAThread]
static void Main()
.............................
......................... --------------------编程问答-------------------- 4楼说的对,
不过程序会提示app.ApartmentState = ApartmentState.STA; 已经过时
还是用newThread.SetApartmentState(ApartmentState.MTA);
好运! --------------------编程问答-------------------- 5楼正解。 --------------------编程问答-------------------- 如果用backgroundWorker出现这种情况怎么解决? --------------------编程问答-------------------- 进csdn就能找到答案! --------------------编程问答-------------------- 楼上的!
我的是在C#.net3.5wince下写的,那个下面Thread没有这个属性,在main函数添加[STAThread]找不到应用,wince下好像没有这个,该怎么啊???
--------------------编程问答-------------------- 我也遇到了这样的问题,待解。。。 --------------------编程问答-------------------- 正解 --------------------编程问答-------------------- 谢谢你的有用信息 --------------------编程问答-------------------- Hey,
I got the answer for this...
Its related to thread state i.e. STA state.
when i start new therad its state is not set to STA. if We set state to STA its work fine for me.
Following code will give an idea about this.
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
t.SetApartmentState(System.Threading.ApartmentState.STA);
t.Start();
public static void ThreadProc()
{
Application.Run(new WsMaster());
}
.
补充:.NET技术 , C#