Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Windows Service stopping immediately
Message
De
01/09/2013 15:10:20
John Baird
Coatesville, Pennsylvanie, États-Unis
 
 
À
01/09/2013 14:47:37
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:
01581799
Vues:
26
>You should put in a try/catch to see if an error is happening. If so, write the message to the Windows event log. This is a good practice for services anyway.
>
>
>>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
>>
We also have our services set up that we can run them as console apps also if there is a problem to solve. Debugging is much easier that way as you have full debugging.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform