Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OnShutdown event in a Windows Service
Message
From
30/03/2014 12:05:25
 
 
To
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:
01597691
Views:
24
Ok, that command takes two seconds to execute. This is why it has some kind of impact on the OnStart() event. By moving the code into the OnStart() event, this allows it to load successfully:
    Protected Overrides Sub OnStart(ByVal toArgs As String())
        oRobot.oWindowsService = Me

        ' If we cannot start
        If Not oRobot.Start() Then
            lStart = False

            ' If this from the Console application
            If Environment.UserInteractive Then
                Exit Sub
            End If

        End If

        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)

        ' Define the timer
        AddHandler oTimer.Elapsed, AddressOf ServiceTimer

        ' Start the timer
        oTimer.Enabled = True

    End Sub
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
Reply
Map
View

Click here to load this message in the networking platform