Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OnShutdown event in a Windows Service
Message
From
29/03/2014 09:56:26
 
 
To
28/03/2014 18:34:16
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:
01597639
Views:
34
>After having thought more of it, I am not sure if this is possible to accomplish.
>
>We cannot use Local System Account as this requires traversing the NAS. So, we need a domain account to run the Windows Service. In that mode, no interaction is allowed. So, if no interaction is allowed, it would then make sense that such functionality is not supported.

Yeah. Looks like the 'hidden form' approach gives you access to the message loop but still doesn't allow interaction with the desktop

>
>If there is a way, I would surely like to know about it. But, I have not found anyone on the net who succeeded to accomplish that. I have seen a lot of pages which deals with such actions but from a Windows form. Thus, a desktop application which is running can respond to an OnShutDown event and advise the user for some decision making.
>
>One way that has been suggested to me would be to use a very small Windows Service, a slave, with Local System Account, with the sole responsability to assure that all related Windows Services are properly closed and restarted when we restart the server. Thus, such service could then notify the user, when he does the restart, that he has to wait as we have some ongoing operations in progress. With Local System Account, the interaction with the desktop is allowed.

That might work but seems (perhaps of necessity) a little convoluted. Haven't looked closely but there are a couple of properties on ServiceBase that might help:
The RequestAdditionalTime() method in the OnStop() might have some effect.
There's also a CanShutDown property which will cause the OnShutdown event to fire - although I'm not sure what you can do with it.

There's also a registry setting which can increase the time the SCM will wait for a service to shutdown. See WaitToKillServiceTimeout.

But, at the end of the day, you should still program so that the service can shut down safely and coherently in a short period of time.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform