Imports System.ServiceProcess Public Class WindowsService Inherits ServiceBase Protected Shared Sub Startup(toArgs As String(), toWindowsService As WindowsService, tlInteractiveWait As Boolean) If toWindowsService Is Nothing Then Throw New ArgumentNullException("instance") End If If Environment.UserInteractive Then toWindowsService.OnStart(toArgs) If tlInteractiveWait Then Console.WriteLine("Press any key to stop service") Console.ReadKey() End If toWindowsService.OnStop() Else Run(toWindowsService) End If End SubAnd, this at the client level:
Public Class Main Inherits Framework.WindowsService Public Sub New() ServiceName = System.Configuration.ConfigurationManager.AppSettings("MyServiceName") End Sub Public Shared Sub Main(toArgs As String()) Startup(toArgs, New Main(), True) End Sub Protected Overrides Sub OnStart(toArgs As String()) MyBase.OnStart(toArgs) End Sub Protected Overrides Sub OnStop() MyBase.OnStop() End Sub End Class