Domanda

Sono nel bel mezzo di costruzione di un semplice servizio di Windows e sto correndo in un piccolo problema.

Il servizio è attivo più che bene, il metodo OnStart crea un processo di lavoro che in ascolto per le connessioni UDP.

Il problema che sto avendo è che quando io sia fare clic su Stop sul servizio, o riavviare, il servizio rimane in esecuzione nel task manager. Non so cosa sto facendo male.

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
È stato utile?

Soluzione

ho postato fondamentalmente la stessa domanda a questo fine settimana, si consiglia di osservare la risposta ci sono arrivato:

Come posso ottenere il mio TCP ascoltatore servizio per terminare in modo corretto?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top