Trouble getting timer tick to fire in Windows Service

  • Thread starter Thread starter Rico
  • Start date Start date
R

Rico

Hello,

I'm trying run a process at regular intervals using a windows service. the
problem is, the timer_tick event doesn't appear to be working. I've written
the following code as a test;

Public Class FileName
Protected Overrides Sub OnStart(ByVal args() As String)



Timer1.Interval = 1000
Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

If Not EventLog.SourceExists("Service1") Then
EventLog.CreateEventSource("Service1", "Application")
End If

EventLog1.Source = "Service1"
EventLog1.WriteEntry("This is a simple event log entry")

End Sub

Needless to say, there are no EventLog entries occurring. I've also tried
to attach to the process but again, it doesn't seem to fire.



Any direction would be greatly appreciated.

Thanks!


Rick
 
Rico said:
I'm trying run a process at regular intervals using a windows service.
the problem is, the timer_tick event doesn't appear to be working. I've
written the following code as a test;

Public Class FileName
Protected Overrides Sub OnStart(ByVal args() As String)

Timer1.Interval = 1000
Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Note that 'System.Windows.Forms.Timer' does not work if its not placed on a
form. You may want to use 'System.Timers.Timer' or 'System.Theading.Timer'
instead.
 
Back
Top