SetApartmentState(ApartmentState state).Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process

 

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);

 

posted @ 2019-05-19 23:17  FredGrit  阅读(291)  评论(0编辑  收藏  举报