Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OnShutdown event in a Windows Service
Message
From
30/03/2014 12:01: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:
01597690
Views:
31
>This sounds interesting tho : http://www.sivachandran.in/2012/03/handling-pre-shutdown-notification-in-c.html

In there, the following explains exactly the situation that we have to negotiate with:

"The limitation of OnShutdown method is, limited time given for the cleanup work and there is no guarantee that other essential services(e.g. DB, EventLog) are running. The last point is the fundamental reason why Microsoft brought this pre-shutdown notification."

I took a look at that approach. So far, I have this:
    Public Sub New()
        CanStop = True
        CanShutdown = True
        CanPauseAndContinue = False

        Dim acceptedCommandsFieldInfo As System.Reflection.FieldInfo = GetType(ServiceBase).GetField("acceptedCommands", _
         System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        If acceptedCommandsFieldInfo Is Nothing Then
            'Throw ApplicationException("acceptedCommands field not found")
        End If
        Dim value As Integer = CInt(acceptedCommandsFieldInfo.GetValue(Me))
        acceptedCommandsFieldInfo.SetValue(Me, value Or SERVICE_ACCEPT_PRESHUTDOWN)
    End Sub
I added the necessary code in the constructor. However, if the last line is executed, the OnStart() will never fire. If I comment that line, the service starts successfully. I have taken a look at examples on the net and they all use it like that. The only difference is that all those examples are C#. I do not know if this could have an impact here.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform