G
Guest
Does anyone have some sample code (in VB.Net) to create a service that uses a
timer to run a function every hour?
Here's my code:
Protected Overrides Sub OnStart(ByVal args() As String)
Dim tmrState As New TimerState
' make a starting entry in the event log
EventLog.WriteEntry("FaxStatus service starting: " &
System.DateTime.Now)
' create a delegate for handling the ticking of the timer
Dim timerDelegate As New TimerCallback(AddressOf CheckStatus)
' create a timer thats waits for 1 min then ticks every hour
Dim tmrTick As New Timer(timerDelegate, tmrState, 1800000, 3600000)
' keep a handle to the timer so it can be disposed
tmrState.tmr = tmrTick
' the main thread does nothing until the timr is disposed
While Not (tmrState.tmr Is Nothing)
Thread.Sleep(0)
End While
End Sub
thx...sonny
timer to run a function every hour?
Here's my code:
Protected Overrides Sub OnStart(ByVal args() As String)
Dim tmrState As New TimerState
' make a starting entry in the event log
EventLog.WriteEntry("FaxStatus service starting: " &
System.DateTime.Now)
' create a delegate for handling the ticking of the timer
Dim timerDelegate As New TimerCallback(AddressOf CheckStatus)
' create a timer thats waits for 1 min then ticks every hour
Dim tmrTick As New Timer(timerDelegate, tmrState, 1800000, 3600000)
' keep a handle to the timer so it can be disposed
tmrState.tmr = tmrTick
' the main thread does nothing until the timr is disposed
While Not (tmrState.tmr Is Nothing)
Thread.Sleep(0)
End While
End Sub
thx...sonny