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

猜你喜欢

转载自www.cnblogs.com/Fred1987/p/10891448.html