2009-12-21 12 views
1

Je suis au milieu de la construction d'un service Windows simple et je suis confronté à un petit problème. Le service s'exécute très bien, la méthode OnStart crée un processus de travail qui écoute les connexions UDP entrantes..NET Déchirer un service Windows

Le problème que je rencontre est que lorsque je clique sur STOP sur le service, ou sur RESTART, le service reste actif dans le gestionnaire de tâches. Je ne sais pas ce que je fais mal.

Imports System.IO 
Imports System.Net.Sockets 
Imports System.Net 
Imports System.Text 

Public Class Service1 
Private ListenSocket As New MyNameSpace.Logging 
Private wt As System.Threading.Thread 

Protected Overrides Sub OnStart(ByVal args() As String) 
    AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionEventRaised 

    'Load Initial IP Details' 
    Try 
     Dim logger As New MyNameSpace.Logging 
     logger.LoadIPDetails() 
    Catch ex As Exception 
     MyNameSpace.ErrorLogging.Log(ex) 
    End Try 

    'Start the listener in a new worker 
    Try 
     Dim ts As System.Threading.ThreadStart 
     ts = AddressOf ListenSocket.ListenForSyslogs 
     wt = New System.Threading.Thread(ts) 
     wt.Start() 
    Catch ex As Exception 
     MyNameSpace.ErrorLogging.Log(ex) 
    End Try 
End Sub 

Protected Overrides Sub OnStop() 
    ' Add code here to perform any tear-down necessary to stop your service. 
    Try 
     wt.Abort() 
     wt = Nothing 

    Catch ex As Exception 
     MyNameSpace.ErrorLogging.Log(ex) 
    End Try 
End Sub 

Protected Overloads Sub UnhandledExceptionEventRaised(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs) 
    If e.IsTerminating Then 
     Dim o As Object = e.ExceptionObject 
     MyNameSpace.ErrorLogging.Log(o) ' use EventLog instead 
    End If 
End Sub 


End Class 

Répondre