Why does the RequestAdditionalTime () method not work when rebooting in Vista / 7?

I did extensive testing of the Windows service that I wrote in C # .Net 3.5. I am having problems getting Windows to give me enough time for my service to work properly when I restart or shut down the computer, even if I call the RequestAdditionalTime () method, which should update SCM and keep my service running. My code works correctly if I manually stopped the service. First of all, I tested this code in Windows Vista and Windows 7, having decided to test the code in Windows Xp, everything worked perfectly. Does anyone know why this call does not work in Vista / 7? I think I need some permission so that the system does not shut down, which I get by default in Xp, but not in Vista / 7.

+7
c # windows-7 windows-vista windows-services
source share
3 answers

If the system does not shut down, your service may request additional time and your process will not be killed.

If the system shuts down, your service must be shut down. You do not even get the normal 30 seconds that a service usually receives. Shutdown is stronger than before.

+6
source share

In the case without shutting down RequestAdditionalTime () must be called more often than every 2 minutes:

protected override void OnStop() { Thread.Sleep(60000); RequestAdditionalTime(180000); Thread.Sleep(60000); RequestAdditionalTime(180000); Thread.Sleep(5000); } 

Please note that despite the name, the time parameter is the required time for a complete shutdown.

+2
source share
+1
source share

All Articles