I'm writing a Windows service which starts a TCP listener. The core code works fine, but I'm having several problems with the mechanics of a Windows service.
Right now, when my service starts up, it creates a thread and starts the TCP listener in the thread. Then, when the service stops, it terminates that thread:
Public Class txnSocketService
Inherits System.ServiceProcess.ServiceBase
Private listenerThread As Thread
Public Sub New()
Me.ServiceName = "txnSocketService"
Me.CanStop = True
Me.CanPauseAndContinue = True
Me.AutoLog = True
End Sub
Shared Sub Main()
System.ServiceProcess.ServiceBase.Run(New txnSocketService)
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
listenerThread = New Thread(AddressOf pmtListener.Main)
listenerThread.IsBackground = True
listenerThread.Start()
End Sub
Protected Overrides Sub OnStop()
listenerThread.Abort()
End Sub
Private Sub InitializeComponent()
'
'txnSocketService
'
Me.ServiceName = "txnSocketService"
End Sub
End Class
Starting up works fine. If I stop the service, however, the service process doesn't terminate. What am I doing wrong?
[By the way, I'm currently doing this on VS2010 Beta 2, if that matters.]