Windows service OnStop wait for finished processing

前端 未结 2 1670
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 05:53

I actually develop a Windows service in VS 2012 / .NET 4.5.

The service is following the scheme of the code snippet below:

  • Using a timer
  • Exec
2条回答
  •  时光说笑
    2020-12-31 06:47

    @Matt - thanks for the great code, really helpful. I found it worked even better if I added another test on _shutdownEvent:

    case 1:  // Process Event
                Process();
                if(_shutdownEvent.WaitOne(0)) break; // don't loop again if a shutdown is needed
    ...
    

提交回复
热议问题