Allow a Service to run as a Console program

** My example is when you put the param "/console", it'll open as Console--else Service

1. Create a new Service Project

2. Change the "Application Type" after to "Console Application" (Properties of Project)

3. Go into the Designer by clicking on InitializeComponent in the Project View on the right side

4. In the Program.Designer.vb file that will open, update Main to this:

' The main entry point for the process
    <MTAThread()>
    <System.Diagnostics.DebuggerNonUserCode()>
    Shared Sub Main(args() As String)
        Dim ServicesToRun() As System.ServiceProcess.ServiceBase

        ' More than one NT Service may run within the same process. To add
        ' another service to this process, change the following line to
        ' create a second service object. For example,
        '
        '   ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
        '
        ServicesToRun = New System.ServiceProcess.ServiceBase() {New Service1}

        If args.Count > 0 Then
            If LCase(args(0)) = "/console" Then
                Dim oRun As New Service1
                oRun.OnStart(args)
            Else
                System.ServiceProcess.ServiceBase.Run(ServicesToRun)
            End If
        Else
            System.ServiceProcess.ServiceBase.Run(ServicesToRun)
        End If
    End Sub
   

(In your main loop, not in OnStart(args), put this to keep it running)

If Environment.UserInteractive Then
            While bRunning
                Threading.Thread.Sleep(1 * 1000)
            End While
    End If

Helpful: UserInteractive

If Environment.UserInteractive Then
Else
End If