Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OnShutdown event in a Windows Service
Message
From
28/03/2014 03:46:46
 
 
To
27/03/2014 16:06:17
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01597504
Message ID:
01597526
Views:
34
.NET has the SystemEvents.SessionEnding event : http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionending(v=vs.110).aspx

It uses the message pump so it's not quite so simple to use in a windows service. MS suggest either using the local system account and setting 'Allow service to interact with desktop' or using a hidden form. See second example here : http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents(v=vs.110).aspx




>Has anyone made use of the OnShutdown event in a Windows Service? I see there is an event for that. So, we can plug code in there. However, this is for someone who would reboot the server. While the service is in a loop, I would like to block the shutdown and send a message to the user, such as we see on regular services where we have to wait until the process finishes its loop, current process or else, and then that warning goes off by itself. There is still the possibility that the user can force an immediate reboot without waiting. But, that is ok. This is just how Windows is. At least, I need to send something to the user so he would know to wait a few seconds for an ongoing process to complete.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform