Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Windows Service stopping immediately
Message
De
01/09/2013 22:32:48
 
 
À
01/09/2013 19:03:01
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:
01581817
Vues:
27
>We don't need to recompile in order to run the service as a Console app for debugging purposes. Our project is a Console app project and here's what my code looks like:

I have done pretty much what was needed to use this infrastructure. I find it interesting. As you said, the control is given to a console app instead of straight to a Windows Service. That is why you are then able to have it run as a console app as well. I changed my project properties to a Console app but I had to adjust manually some things in the Application.Designer.vb and Resources.Designer.vb files. I believe this is a bug in the VS 2012 interface when switching the project type.

I am wondering however how you workaround this situation:

"No accessible 'Main' method with an appropriate signature was found in 'MyProject.Main'."

Because, initially, this is what I had and when I succeeded to have it working as a Windows Service, this went away. Now, that I have changed it back to this design, I have this situation back. This is the only situation remaining before I can do a test. I resolved all other errors.

My entry point is like this:
Imports System.ServiceProcess

Public Class Main

    Shared oWindowsService As WindowsService = Nothing

    Public Sub New()
    End Sub

    Private Shared Sub Main()

        ' If this from the Windows Service
        If Not Environment.UserInteractive Then
            Dim loWindowsService As ServiceBase()
            loWindowsService = New ServiceBase() {New WindowsService()}
            ServiceBase.Run(loWindowsService)
        Else
            oWindowsService = New WindowsService()
            oWindowsService.Start()
            Console.ReadLine()
            oWindowsService.Stop2()
        End If

    End Sub

End Class

Partial Public Class WindowsService
    Inherits ServiceBase

    Public Sub New()
        CanStop = True
        CanShutdown = True
        CanPauseAndContinue = False
    End Sub

    Protected Overrides Sub OnStart(args As String())
        ' startup code here
        'Console.WriteLine("Done With OnStart");
    End Sub

    Protected Overrides Sub OnStop()
        ' stop code here
    End Sub

    Protected Overrides Sub OnShutdown()
        ' TODO: There may be a bug in the .NET Framework in that this method
        ' is not being called on system shutdown for SYSTEM account services.
        ' Not sure when/if it will be fixed, but I'm putting code here to stop
        ' stuff on the off-chance that it will be called eventually.

        ' stop code  here
    End Sub

    ' These 2 methods are only used when not runnning as a Service, for testing from a Console window.
    Public Sub Start()
        Me.OnStart(Nothing)
    End Sub

    Public Sub Stop2()
        Me.OnStop()
    End Sub

End Class
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