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);
本文详细解释了在.NET环境中遇到'System.Threading.ThreadStateException'异常的原因,该异常通常发生在尝试从非单线程公寓(STA)模式的线程调用OLE操作时。文章提供了设置线程为STA模式的代码示例,以确保在调试过程中正确调用OLE。
1227

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



