Windows Services & System Shutdown RRS feed

  • Question

  • I am writing a Windows Service that connects to a remote Web Service and performs a number of data transfer operations in the background. Being new to Windows Services, I was wondering as to what is the default behaviour when the system is shutdown (under normal circumstances) while a background Windows Service is in the middle of an operation.

    Does the system notify the user that a background process is performing an operation? If not, is there any way of notifying the system about the running process?

    Many Thanks in advance...
    Monday, August 8, 2005 3:48 PM


  • 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.
    Monday, August 8, 2005 4:53 PM