diddydustin
Programmer
Hey guys,
I'm having a weird problem. I have a Windows service in .Net that runs fine for a while but then seems to stop. Here is a bit of the timer code:
' AmazonQue
' The registry values for storing the time intervals are:
' HKEY_LOCAL_MACHINE/SOFTWARE/AmazonQue/SuccessTime
' Time used if we found something in the que
' HKEY_LOCAL_MACHINE/SOFTWARE/AmazonQue/FailTime
' Time used if there is nothing in the que and we are waiting
Imports System.ServiceProcess
Imports System.Security.Permissions
Imports Microsoft.Win32
Imports System.Math
<Assembly: RegistryPermissionAttribute( _
SecurityAction.RequestMinimum, All:="HKEY_LOCAL_MACHINE")>
Public Class Service
Inherits System.ServiceProcess.ServiceBase
#Region " Definitions "
' Max ISBNs we will fetch
Shared ISBN_MAX = 10
' Stored procedure to return ISBNs
Shared STOR_PROC = "spSel_vwQue"
' Seconds for poll if success
Shared SUCCESS_SEC = Int(RegValue(RegistryHive.LocalMachine, _
"SOFTWARE\AmazonQue", "SuccessTime"))
' Seconds for poll if fail
Shared FAIL_SEC = Int(RegValue(RegistryHive.LocalMachine, _
"SOFTWARE\AmazonQue", "FailTime"))
' Default values for our timer
Shared SUCCESS_DEFAULT = 1
Shared FAIL_DEFAULT = 60
' Our timer object
Dim tmrClock As New System.Timers.Timer
#End Region
#Region " Timer "
Public Shared Function StartTimer(ByRef myClock As System.Timers.Timer)
AddHandler myClock.Elapsed, AddressOf OnTimedEvent
With myClock
If SUCCESS_SEC <> 0 Then
.Interval = SUCCESS_SEC * 1000
Else
.Interval = SUCCESS_DEFAULT * 1000
End If
.Enabled = True
End With
End Function
Public Shared Function StopTimer(ByRef myClock As System.Timers.Timer)
myClock.Enabled = False
End Function
Private Shared Sub OnTimedEvent(ByVal source As Object, ByVal e As System.Timers.ElapsedEventArgs)
If (Begin()) Then
If SUCCESS_SEC <> 0 Then
source.Interval = SUCCESS_SEC * 1000
Else
source.Interval = SUCCESS_DEFAULT * 1000
End If
Else
If FAIL_SEC <> 0 Then
source.Interval = FAIL_SEC * 1000
Else
source.Interval = FAIL_DEFAULT * 1000
End If
End If
End Sub
#End Region
#Region " Que "
Public Shared Function Begin() As Boolean
Dim objDataSet As New System.Data.DataSet
If (CheckQue(objDataSet) > 0) Then
ExecQue(objDataSet)
Return True
Else
Return False
End If
End Function
To resolve my issue I have to restart the service, but I'd like for it to constantly be able to run... can anyone see what my problem could be?
Thanks
Dustin
I'm having a weird problem. I have a Windows service in .Net that runs fine for a while but then seems to stop. Here is a bit of the timer code:
' AmazonQue
' The registry values for storing the time intervals are:
' HKEY_LOCAL_MACHINE/SOFTWARE/AmazonQue/SuccessTime
' Time used if we found something in the que
' HKEY_LOCAL_MACHINE/SOFTWARE/AmazonQue/FailTime
' Time used if there is nothing in the que and we are waiting
Imports System.ServiceProcess
Imports System.Security.Permissions
Imports Microsoft.Win32
Imports System.Math
<Assembly: RegistryPermissionAttribute( _
SecurityAction.RequestMinimum, All:="HKEY_LOCAL_MACHINE")>
Public Class Service
Inherits System.ServiceProcess.ServiceBase
#Region " Definitions "
' Max ISBNs we will fetch
Shared ISBN_MAX = 10
' Stored procedure to return ISBNs
Shared STOR_PROC = "spSel_vwQue"
' Seconds for poll if success
Shared SUCCESS_SEC = Int(RegValue(RegistryHive.LocalMachine, _
"SOFTWARE\AmazonQue", "SuccessTime"))
' Seconds for poll if fail
Shared FAIL_SEC = Int(RegValue(RegistryHive.LocalMachine, _
"SOFTWARE\AmazonQue", "FailTime"))
' Default values for our timer
Shared SUCCESS_DEFAULT = 1
Shared FAIL_DEFAULT = 60
' Our timer object
Dim tmrClock As New System.Timers.Timer
#End Region
#Region " Timer "
Public Shared Function StartTimer(ByRef myClock As System.Timers.Timer)
AddHandler myClock.Elapsed, AddressOf OnTimedEvent
With myClock
If SUCCESS_SEC <> 0 Then
.Interval = SUCCESS_SEC * 1000
Else
.Interval = SUCCESS_DEFAULT * 1000
End If
.Enabled = True
End With
End Function
Public Shared Function StopTimer(ByRef myClock As System.Timers.Timer)
myClock.Enabled = False
End Function
Private Shared Sub OnTimedEvent(ByVal source As Object, ByVal e As System.Timers.ElapsedEventArgs)
If (Begin()) Then
If SUCCESS_SEC <> 0 Then
source.Interval = SUCCESS_SEC * 1000
Else
source.Interval = SUCCESS_DEFAULT * 1000
End If
Else
If FAIL_SEC <> 0 Then
source.Interval = FAIL_SEC * 1000
Else
source.Interval = FAIL_DEFAULT * 1000
End If
End If
End Sub
#End Region
#Region " Que "
Public Shared Function Begin() As Boolean
Dim objDataSet As New System.Data.DataSet
If (CheckQue(objDataSet) > 0) Then
ExecQue(objDataSet)
Return True
Else
Return False
End If
End Function
To resolve my issue I have to restart the service, but I'd like for it to constantly be able to run... can anyone see what my problem could be?
Thanks
Dustin