Service with Timer

Koolaidman

New member
Joined
Nov 15, 2004
Messages
2
Programming Experience
10+
Hi,

I am having a problem with a service I have created which uses a System Timer. Basically, what is happening is the Timer seems to just stop running for no reason what so ever. I have created the timer as
X
.Timer1 = New System.Timers.Timer

In the OnStart section of the service, i have added
Timer1.Enabled = True

And Then

PrivateSub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed

Try
Timer1.Enabled = False
<..Routine..>
Catch e as Exception
<..Routine..>
Finally
Timer1.Enabled = True
End Try

End Sub

If anyone has any clues as to what I may have done wrong that would cause the timer to just stop working.

Matt
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
VB.NET:
privarte Timer1 = New System.Timers.Timer

Private Sub Form_Load(....) Handles MyBase.Load
  Timer1.Interval = 50000  'Integer value, 1000 = 1second
  Timer1.Enabled = True
End Sub

PrivateSub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Tick

Try
<..Routine..>
Catch e as Exception
<..Routine..>
End Try

End Sub
 

Koolaidman

New member
Joined
Nov 15, 2004
Messages
2
Programming Experience
10+
Thank you for the response. However what you have written does not compile. There are errors caused by "Handles" needing to be declared as WithEvents. Also, I don't believe that Tick is a property of a System Timer.

Matt
 
Top Bottom