Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
OnShutdown event in a Windows Service
Message
De
30/03/2014 12:01:17
 
 
À
30/03/2014 04:50:17
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01597504
Message ID:
01597690
Vues:
32
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform