I have a Windows service class derived from ServiceBasethat uses System.Timers.Timerto run code at frequent intervals. The handlers for OnStopand OnPauseuse some signaling using the timer thread to check if the timer is working and is waiting for it to complete.
Is there a recommended way to handle delay errors in this situation, for example, if the handler waits an unacceptably long time to stop the timer stream?
Should I just keep waiting until SCM backtracks (but this will cause the service to be unable to do anything with the service except to kill the process, and sometimes rebooting is the only way to restart it)? Or could I throw an exception (will we leave it in a similar state or just abort the stop / pause request)?
I would prefer if I can reject the pause / stop request and leave the SCM in a state where the user can try to pause / stop again. I could interrupt the timer stream, but sometimes it was blocked on other resources, which I would prefer it to wait until completion, and just log an error so that the administrator can stop later.
source
share