今天在使用多线程时遇到异常
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