Popular Posts

Saturday, December 27, 2008

Windows Service Timer Fires only once

Problem Script

Public Class FileTransferAgentService

Protected Overrides Sub OnStart(ByVal args() As String)
Dim FTATimer As System.Threading.Timer
Const timerInterval As Integer = 60000
Dim timerDelegate As Threading.TimerCallback = AddressOf EventAction
FTATimer = New System.Threading.Timer(timerDelegate, Me, timerInterval, timerInterval)
EventLog.WriteEntry("FTA started.")
End Sub

:
:
:
End Class


Solution Script: Delcare the Timer thread as Global to the Class:

Public Class FileTransferAgentService

Dim FTATimer As System.Threading.Timer
Const timerInterval As Integer = 60000
Dim timerDelegate As Threading.TimerCallback = AddressOf EventAction

Protected Overrides Sub OnStart(ByVal args() As String)
FTATimer = New System.Threading.Timer(timerDelegate, Me, timerInterval, timerInterval)
EventLog.WriteEntry("FTA started.")
End Sub

:
:
End Class

No comments:

Post a Comment