J
John Wright
I am creating a windows service that I need to fire off every 4 hours to
check a database for records. If there are records, then I need to call
a web service to process them. After much reading I found out that I needed
to use the Threading.Timer and a call back to fire off. Not a problem.
However, I need this to run every 4 hours (or any value that is set in the
database). I am including some of the code I need help on. I need to check
the database for the timeout value and reset it after I run the checkDB in
case we need to readjust the time between checks. I figured it would be
easier to set the value in a database than to hard code it and recompile
when we need to change the time between checks? Should this check be in
the OnStart or in the CheckDB as the last command to reset the timer's interval
between callsback? Does OnStart fire each time the timer is invoked or only
when the service is started? Any other suggestions would be appreciated
this timer value needs to be able to be changed without a recompile.
John
Private stateTimer As Threading.Timer
Dim oCallBack As New TimerCallback(AddressOf checkDB)
Protected Overrides Sub OnStart(ByVal args() As String)
evEPNMatrixLog.WriteEntry("EPNSync Started started: " & Now)
objDAL = New DALManager
objDAL.ConnectionString = My.Resources.ConnectionString
objDAL.ProviderName = My.Resources.ProviderName
objParam = New DbParameterCollection
stateTimer = New Timer(oCallBack, Nothing, 60000, 60000) --->I need
to set this value from a database
End Sub
Private Sub CheckDB(ByVal state As Object)
'do processing here
'check the database for the next check time and reset the timer
End Sub
check a database for records. If there are records, then I need to call
a web service to process them. After much reading I found out that I needed
to use the Threading.Timer and a call back to fire off. Not a problem.
However, I need this to run every 4 hours (or any value that is set in the
database). I am including some of the code I need help on. I need to check
the database for the timeout value and reset it after I run the checkDB in
case we need to readjust the time between checks. I figured it would be
easier to set the value in a database than to hard code it and recompile
when we need to change the time between checks? Should this check be in
the OnStart or in the CheckDB as the last command to reset the timer's interval
between callsback? Does OnStart fire each time the timer is invoked or only
when the service is started? Any other suggestions would be appreciated
this timer value needs to be able to be changed without a recompile.
John
Private stateTimer As Threading.Timer
Dim oCallBack As New TimerCallback(AddressOf checkDB)
Protected Overrides Sub OnStart(ByVal args() As String)
evEPNMatrixLog.WriteEntry("EPNSync Started started: " & Now)
objDAL = New DALManager
objDAL.ConnectionString = My.Resources.ConnectionString
objDAL.ProviderName = My.Resources.ProviderName
objParam = New DbParameterCollection
stateTimer = New Timer(oCallBack, Nothing, 60000, 60000) --->I need
to set this value from a database
End Sub
Private Sub CheckDB(ByVal state As Object)
'do processing here
'check the database for the next check time and reset the timer
End Sub