Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer in Windows service stopping on i't's own

Status
Not open for further replies.

diddydustin

Programmer
Jul 30, 2002
181
US
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
 
if you want to run a timer forever, I would look into the system.threading.timer it has less issues.

with the timer you use you will get memory problems. Look at the memory usage of your service and see how it grows, normally it should be cleaned by the GC and it probably is. But all memory reserved for a certain app will remain reserved untill it is killed (if I'm not misstaken).

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top