Windows service Timer elapsed event not firing

  • Thread starter Thread starter Sagar
  • Start date Start date
S

Sagar

Hi,

I wrote a simple windows service program with a timer. The timer
doesnt seem to be firing the elapsed event.

Can someone tell why ? whats the problem with this code ?

Thanks,
Anand
-----------------------

Imports System.IO
Imports System.Timers
Public Class goodmorningalarm

Private WithEvents myTimer As New System.Timers.Timer(100)

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set
things
' in motion so your service can do its work.


AddHandler myTimer.Elapsed, AddressOf DoSomething
myTimer.Start()
myTimer.Enabled = True

End Sub

Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop
your service.
myTimer.Enabled = False
End Sub

Function DoSomething() As Integer
MsgBox("test")

'Dim wr As New StreamWriter("c:\test.txt")
'wr.Write("Hello")

Return 1
End Function


End Class
 
Sagar said:
Hi,

I wrote a simple windows service program with a timer. The timer
doesnt seem to be firing the elapsed event.

Can someone tell why ? whats the problem with this code ?

Thanks,
Anand

Maybe, the service has blown-up/aborted and you don't know it.
 
Doesnt help, I would've expected a precise reply.

Anyways, Are you saying the code is correct and should work without
issues ?

I am doing this coding in vb.net 2008

Regards,
Anand
 
Sagar said:
Doesnt help, I would've expected a precise reply.

Anyways, Are you saying the code is correct and should work without
issues ?

No, I am saying you don't have a try/catch no where to be found in the
code, and it may have blown up. Do you even know how to debug a Windows
service by attaching a debugger to the Window service process?

If things are not firing, it's because it never made it to do the firing
is the most likely cause of the problem.
 
Back
Top