今天在使用多线程时遇到异常
System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.
网上查找了一下,当线程处于对于方法调用来说无效的 ThreadState 时引发的异常,
解决方法,在启动线程前先调用SetApartmentState (ApartmentState.STA)设置线程
http://social.msdn.microsoft.com/Forums/en/winforms/thread/180fde7b-ee75-4a6e-bb8e-c56b1552415d
本文介绍了一种在使用多线程编程时遇到的异常——System.Threading.ThreadStateException,并提供了具体的解决方案。该异常通常发生在线程状态不正确的情况下,解决方法是在启动线程前调用SetApartmentState(ApartmentState.STA)。
1万+

被折叠的 条评论
为什么被折叠?



