SetApartmentState(ApartmentState state).Ensure that your Main function has STAThreadAttribute marked

 

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.'spa

 

Thread exportThread = new Thread(() =>
              {
                 
              });
            exportThread.SetApartmentState(ApartmentState.STA);

 

 Sets the apartment state of a thread before it is started.debug

[SecuritySafeCritical]
public void SetApartmentState(ApartmentState state);code

相关文章
相关标签/搜索