|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
OnShutdown not executing in Windows serviceRestarting Windows seems not to fire the OnShutdown event in the
Windows Service. Does not work on Windows XP SP2 and not on Windows 2003 Server SP1. OnStart and OnStop do work fine. Steps to reproduce: Create a Windows service in VB.NET using VS 2005. Set CanShutdown property to true. Implement Protected Overrides Sub OnShutdown() Diagnostics.EventLog.WriteEntry(Me.ServiceName, "Shutdown") End Sub Start Service and Reboot. I quote the MSDN:
This event occurs only when the operating system is shut down, not when the computer is turned off. I'd also like to see what this really means. :-) Did you try to implement EventLog.WriteEntry(Me.ServiceName, "OnStop") into an **OnStop** event? Maybe, when you reboot the computer it fires the OnStop event instead. Also, did you try just pressing the power button instead of the reboot? Maybe then the OnShutdown will fire. Show quote "Peter Meinl" <p**@petermeinl.de> wrote in message news:OtForOwBGHA.1864@TK2MSFTNGP12.phx.gbl... > Restarting Windows seems not to fire the OnShutdown event in the > Windows > Service. Does not work on Windows XP SP2 and not on Windows 2003 > Server SP1. > OnStart and OnStop do work fine. > > Steps to reproduce: > Create a Windows service in VB.NET using VS 2005. > Set CanShutdown property to true. > > Implement > Protected Overrides Sub OnShutdown() > Diagnostics.EventLog.WriteEntry(Me.ServiceName, "Shutdown") > End Sub > > Start Service and Reboot. > > To me shutting down means cleanly shutting down or restarting the OS and
turning off means switching the power off and thus giving the OS no chance to fire any events. Yes, I also implemented OnStop writing to the EventLog. As expected OnStop only executes when the service is stopped using the management console. Show quote "Zvonko Keber" <zvke***@yahoo.com> wrote in message news:OzaZHcwBGHA.228@TK2MSFTNGP12.phx.gbl... >I quote the MSDN: > > This event occurs only when the operating system is shut down, not when > the computer is turned off. > > I'd also like to see what this really means. :-) > > Did you try to implement EventLog.WriteEntry(Me.ServiceName, "OnStop") > into an **OnStop** event? > Maybe, when you reboot the computer it fires the OnStop event instead. > > Also, did you try just pressing the power button instead of the reboot? > Maybe then the OnShutdown will fire. > > > "Peter Meinl" <p**@petermeinl.de> wrote in message > news:OtForOwBGHA.1864@TK2MSFTNGP12.phx.gbl... >> Restarting Windows seems not to fire the OnShutdown event in the >> Windows >> Service. Does not work on Windows XP SP2 and not on Windows 2003 >> Server SP1. >> OnStart and OnStop do work fine. >> >> Steps to reproduce: >> Create a Windows service in VB.NET using VS 2005. >> Set CanShutdown property to true. >> >> Implement >> Protected Overrides Sub OnShutdown() >> Diagnostics.EventLog.WriteEntry(Me.ServiceName, "Shutdown") >> End Sub >> >> Start Service and Reboot. >> >> > > |
|||||||||||||||||||||||