문제

If my OnStart method is

while (true)
{
  // do stuff
}

Will OnStop run in this case? Or do I have to create a new thread such that the thread OnStart is running on unblocks?

도움이 되었습니까?

해결책

The thread that calls OnStart doesn't "belong" to you. You're not meant to block it. You should use it to set up any threads, any timers, any listeners on the network, etc, and then return from the OnStart method.

Only when you return from OnStart will the service control manager transition your service from Starting to Started.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top