Service runs then dies

后端 未结 2 1919
无人共我
无人共我 2021-01-23 17:37

I\'m running Win 7 Pro 64-bit. I wrote a service in C# using the .NET 4 framework. It installs properly and starts to run. I know that it runs because it writes some output t

2条回答
  •  离开以前
    2021-01-23 17:58

    If you're running your code directly from within the Service's Start method, this behavior can easily occur. The problem is that the service's Start method is expected to start the service and immediately return. If it sits there executing code, Windows will kill the service on you.

    The correct way to handle this is to have the service's Start() method run your code in a dedicated thread. It shouldn't really need anything except the thread creation and an immediate return. If this is the problem, just setup a foreground thread and put your logic there, and it will likely work correctly.

提交回复
热议问题