Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Windows Service stopping immediately
Message
De
01/09/2013 15:07:26
 
 
À
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:
01581798
Vues:
21
>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.

Good one, but I still cannot find the reason.

To simplify things up, I have put everything in one class:
Imports System.Timers
Imports System.ServiceProcess
Imports System
Imports System.Diagnostics

Public Class Main
    Inherits ServiceBase

    Shared Sub Main(ByVal toArgs As String())
        Dim lcSource As String
        Dim lcLog As String
        Dim lcEvent As String

        'Startup(toArgs, New Main())
        Try
            Dim loMain As Main = New Main
            loMain.OnStart(toArgs)
        Catch loError As Exception
            lcSource = "My application"
            lcLog = "Application"
            lcEvent = loError.Message
            EventLog.WriteEntry(lcSource, lcEvent)
        End Try

        lcSource = "My application"
        lcLog = "Application"
        lcEvent = "This is just a log to see that we are at the end of Main"
        EventLog.WriteEntry(lcSource, lcEvent)
    End Sub

    Protected Overrides Sub OnStart(ByVal toArgs As String())
        Dim lcSource As String
        Dim lcLog As String
        Dim lcEvent As String

        Try
            MyBase.OnStart(toArgs)

            ' Start the timer
            oTimer.Enabled = True

        Catch loError As Exception
            lcSource = "My application"
            lcLog = "Application"
            lcEvent = loError.Message
            EventLog.WriteEntry(lcSource, lcEvent)
        End Try

    End Sub

    Protected Overrides Sub OnStop()
        Dim lcSource As String
        Dim lcLog As String
        Dim lcEvent As String

        Try
            MyBase.OnStop()
        Catch loError As Exception
            lcSource = "My application"
            lcLog = "Application"
            lcEvent = loError.Message
            EventLog.WriteEntry(lcSource, lcEvent)
        End Try

    End Sub

    Private Sub ServiceTimer(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)
        Dim lcSource As String
        Dim lcLog As String
        Dim lcEvent As String

        Try

        Catch loError As Exception
            lcSource = "My application"
            lcLog = "Application"
            lcEvent = loError.Message
            EventLog.WriteEntry(lcSource, lcEvent)
        End Try

    End Sub
The only event added to the Event viewer is the one Main() as the OnStart() event does not fall into an error.
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
Répondre
Fil
Voir

Click here to load this message in the networking platform