.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Windows Services & System Shutdown
 

Windows Services & System Shutdown

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...
albuquerquev
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.
James Kovacs
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.
James Kovacs

You can use google to search for other answers

Custom Search

More Threads

• Encoding problem
• Process.Start() - prevent reuse of existing
• Multiple Text Encodings in single XML file.
• Assign parts of binary array to different variable types
• populating a List<> of objects
• Updates on present COM ports?
• application doesn't run in the other computer
• Possible bug in System.Net.HttpListenerRequest
• Inserting a space in a title case delimited string
• Convert DateTime between different TimeZone