.NET Windows Service needs to use STAThread

后端 未结 5 2255
野性不改
野性不改 2020-12-01 08:50

I have created a Windows Service that will be calling out to some COM components, so I tagged [STAThread] to the Main function. However, when the timer fires, it reports MT

5条回答
  •  孤街浪徒
    2020-12-01 09:03

    That cannot work in a service, the thread that calls your Main() method was already started by the service manager. You'll need to create a separate thread that is initialized with Thread.SetApartmentState() and pumps a message loop.

提交回复
热议问题