Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Windows Service stopping immediately
Message
De
01/09/2013 14:11:58
 
 
À
01/09/2013 02:53:20
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:
01581778
Message ID:
01581790
Vues:
35
I think the issue is related to the Windows Service does not wait for the timer. For example, if I execute it from the EXE, I can see a message box at the end showing a message that tells me that the OnStop() event was reached. So, while the message is showing, I can see the executable in the Task manager. Then, I click ok and the OnStop() finishes making the executable to complete and it goes out of the Task manager.

So, from the Services interface or from the sc command, I believe for the windows service to properly run, it has to fall into the wait step for the timer to kick in. But, this does not seem to happen as, even if the timer is activated at the end of the OnStart() event, it falls right away in the OnStop() event making the executable to disappear from the memory. This is what I can see from the Task manager.

My Main class is like this:
Public Class Main
    Inherits WindowsService

    Shared Sub Main(ByVal toArgs As String())
        Startup(toArgs, New Main(), True)
    End Sub
And, the base class:
Imports System.ServiceProcess

Public Class WindowsService
    Inherits ServiceBase

    Public oTimer As New System.Timers.Timer(5000)

    Protected Shared Sub Startup(toArgs As String(), toWindowsService As WindowsService, tlInteractiveWait As Boolean)
        toWindowsService.OnStart(toArgs)
    End Sub

    Protected Overrides Sub OnStart(ByVal toArgs As String())
        MyBase.OnStart(toArgs)

        ' Define the timer
        AddHandler oTimer.Elapsed, AddressOf ServiceTimer

        ' Start the timer
        oTimer.Enabled = True

        System.Windows.Forms.MessageBox.Show("End")
    End Sub

    Protected Overrides Sub OnStop()
        MyBase.OnStop()
    End Sub

    Private Sub ServiceTimer(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)
    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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform