ServiceBase.OnShutdown Method
.NET Framework 2.0
When implemented in a derived class, executes when the system is shutting down. Specifies what should happen immediately prior to the system shutting down.
Namespace: System.ServiceProcess
Assembly: System.ServiceProcess (in system.serviceprocess.dll)
Assembly: System.ServiceProcess (in system.serviceprocess.dll)
Use OnShutdown to specify the processing that occurs when the system shuts down. Often, OnShutdown will be similar to the processing in OnStop. This event occurs only when the operating system is shut down, not when the computer is turned off.
OnShutdown is expected to be overridden when the CanShutdown property is true.
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Override OnShutdown and invoke OnStop
Note: http://blogs.msdn.com/b/bclteam/archive/2007/11/01/change-in-system-serviceprocess-shutdown-is-coming-in-3-5-rtm-inbar-gazit.aspx
"In all current versions of the Framework we do not close the actual service when we get a shutdown request from the OS. Instead we just call OnShutdown and hope that the user has overridden this method and called Stop() themselves. We found out that many developers didn’t know they had to do that and this is a major issue when shutting down Vista laptops as it can add 10-20 seconds, for each managed service, to the time you have to wait before the machine is turned off."
On an HPt5740 thin client with XP Embedded and "HP .NET Framework 2.0 SP1 for Thin Clients", failure to override OnShutdown and invoke OnStop results in sporadic system hang - necessitating a hard power off to recover.
"In all current versions of the Framework we do not close the actual service when we get a shutdown request from the OS. Instead we just call OnShutdown and hope that the user has overridden this method and called Stop() themselves. We found out that many developers didn’t know they had to do that and this is a major issue when shutting down Vista laptops as it can add 10-20 seconds, for each managed service, to the time you have to wait before the machine is turned off."
On an HPt5740 thin client with XP Embedded and "HP .NET Framework 2.0 SP1 for Thin Clients", failure to override OnShutdown and invoke OnStop results in sporadic system hang - necessitating a hard power off to recover.
- 9/2/2010
- ScottWelker