We have a .NET Windows Service that occasionally shuts down on one particular server, about three times in the last month. Logging shows that the OnStop method is being called, so I don’t think the service is crashing. However, we don’t know what’s shutting down the service.
Is there any way to find out what’s shutting down the service? Is there anything I can log during OnStop? The Windows Event Viewer just shows application shut down and the security log does not show any user account authenticated at the time.
The service is running in .NET 3.5 SP1 on Windows Server 2003 SP2 (5.2.3790).
There are no service dependencies. This service doesn’t depend on any other services and no other services depend on this service.
There is no way to tell from within the service since this called from the SCM – whoever asked SCM to stop your service isn’t visible to the service…
I think your main option is checking the EventLog around that time… are other services being shutdown too ? is any scheduled taks running etc. ?
A “rather dirty” option (last resort/desperate) would be to set CanStop to false… in this case there will be someone seeing a problem in stopping your service and “hopefully” ask you why your service is not stoppable…