stopping system .threading.timer
-
assuming arrival method is still executing after say 40s seconds . how can i prevent the service from calling another instance pf arrival method Public Class intestService Protected Overrides Sub OnStart(ByVal args() As String) Dim tDelegate As Threading.TimerCallback = AddressOf Arrival oTimer = New System.Threading.Timer(tDelegate, Me, 10, 40) End Sub Public Sub Arrival(ByVal sender As Object) 'File.AppendAllText("C:\test4.txt", "AuthorLogService fires arrival at " & Now.ToString()) Try ' Catch ex As Exception log.WriteEntry(ex.Message, EventLogEntryType.Error) End Try End Sub Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service. End Sub End Class
-
assuming arrival method is still executing after say 40s seconds . how can i prevent the service from calling another instance pf arrival method Public Class intestService Protected Overrides Sub OnStart(ByVal args() As String) Dim tDelegate As Threading.TimerCallback = AddressOf Arrival oTimer = New System.Threading.Timer(tDelegate, Me, 10, 40) End Sub Public Sub Arrival(ByVal sender As Object) 'File.AppendAllText("C:\test4.txt", "AuthorLogService fires arrival at " & Now.ToString()) Try ' Catch ex As Exception log.WriteEntry(ex.Message, EventLogEntryType.Error) End Try End Sub Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service. End Sub End Class
Dim TimerThreadIsRunning As Boolean
Set it to true when you start your thread, and back to false at the end of Arrival method. Start the thread only if the boolean is false.My advice is free, and you may get what you paid for.