Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OnShutdown event in a Windows Service
Message
From
30/03/2014 04:08:58
 
 
To
29/03/2014 20:40:01
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:
01597672
Views:
24
>I have found what looked like a perfect way to get a hold on this:
>
>
>    Protected Overrides Sub OnShutdown()
>
>        ' If the robot is busy
>        If oRobot.lBusy Then
>            oRobot.lShutDown = True
>            RequestAdditionalTime(30000)
>        Else
>
>            ' If we cannot stop the robot
>            If Not oRobot.StopRobot() Then
>
>            End If
>
>        End If
>
>    End Sub
>
>
>Basically, I added a global property in the class lBusy. When the robot loop is in progress, this is True. If this is True, additional requested time will be applied.
>
>So far so good, I can see it goes in there, it sees it is busy, it requests additional time, it goes back in here a second time, and this will go until the robot is no longer busy.
>
>The problem here is I am loosing resources. The robot needs to have access to drives and things like that. As the shutdown event is proceeding with whatever it can, it starts by stopping other services, my robot is still running, but then it cannot write a file, communicate with SQL Server and so on.
>
>So, this thinking was good but it would only work if I can put a hold on all other shutdown operations until this one is clean. And, I do not see how that could be possible. So, as resources are needed, I guess we will have to remain with those procedures. Someone has to initiate a stop of all the robots from the Web interface. That will stop them all. As no shutdown is effective, all resources needed as still available. So, if a robot is not busy, it closes, otherwise, it will close after its process. Then, someone can initiate the shutdown request.
>
>Unless you see a way to apply a lock right at the top of the shutdown chain, I really do not see how this could be possible.

Seems you can set SCM service shutdown order using HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\PreshutdownOrder.
Also, there is the SetProcessShutdownParameters func : http://msdn.microsoft.com/en-us/library/windows/desktop/ms686227(v=vs.85).aspx - but I'm not sure it would help.

But I don't think any of the above will get round the time limit when there is a system shutdown - only the registry WaitToKillServiceTimeout affects that - and, AFAICS, that value is the time to allowed to shut down *all* services.

Don't know what would happen if you set a high priority task to run on shutdown and made that responsible for shutting down the services. Might be an alternative?

But, as before, the safest approach is to make service processes more atomic (i.e. interruptable). Can you give an example of a service job where that cannot be done ?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform