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.'
Thread exportThread = new Thread(() => { }); exportThread.SetApartmentState(ApartmentState.STA);
Sets the apartment state of a thread before it is started.
[SecuritySafeCritical]
public void SetApartmentState(ApartmentState state);
博客提到System.Threading.ThreadStateException异常,指出在进行OLE调用前当前线程必须设置为单线程单元(STA)模式,要确保Main函数有STAThreadAttribute标记,还介绍了在启动线程前设置线程单元状态的方法。
1218

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



