Trouble getting timer tick to fire in Windows Service

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
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top