Handling delays during stop/pause requests on Windows service
I have a Windows service class deriving from ServiceBase that uses a System.Timers.Timer to run code at frequent intervals. The handlers for OnStop and OnPause use some signalling with the timer thread to check if the timer is still running and waits for it to finish. Is there a recommended way of handling delay errors in this situation, such as if the handler is waiting for an unacceptably long time for the timer thread to stop? Should I just continue waiting until the SCM gives up (but that will put the service into a state where you can't do anything with the service except kill the process