How to process the PreShutdown event in a managed Windows service
If you liked the post about Hyper-V guests in different time zones, here is one more article that comes from our development work on the new OpenStack and Hyper-v based setup of Atomia Hosting Platform.
Several of our products ship some windows services which we use to do periodic background tasks. For example, Automation Server uses a service to perform long-running automation tasks. During a system shutdown, it is important that the service has enough time to cleanly exit and not be terminated in the middle of some complex operation.
Whereas Windows will not shutdown until all applications in the user’s session are properly closed, this does not hold true for services, which only have 12 seconds to process a Shutdown notification, which might be too short for your service. The good news is that Microsoft introduced the PreShutdown event for services in Vista, which you can use in your service’s code to get 3 extra minutes (or even more) to shutdown your service.
Read more on how to develop your service’s shutdown behavior after the break.