The Service Control Manager will send a shutdown notification to your Windows Service (via OnShutdown*) informing it that the system is shutting down. The SCM will wait for your service to end before rudely terminating it after a timeout. (I don't recall the exact timeout, but it's something on the order of 30 seconds.) This will give you an opportunity to wait for any pending I/O, such as a web service call, to complete or cancel it.
Introduced in .NET Framework 2.0 is the void RequestAdditionalTime(int milliseconds) method, which will extend the timeout period and prevent the SCM from displaying "Not responding" for the service. This can only be called from OnContinue, OnPause, OnStart, and OnStop. You can't call it from OnShutdown.
* N.B. To receive the OnShutdown notification, you must set CanShutdown to true. |