How to use Timer in Windows Service

You cannot use Timer Control in windows service it is because Timer Control is located at System.Windows.Forms.

Instead, use server timers from Timer namespace. To do this,

Friend WithEvents mTimer as New Timer.Timer

Protected Overrides Sub OnStart(ByVal args() As String)
mTimer.Interval = 6000 ’6 seconds

mTimer.Enable = true
End Sub
Private Sub mTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles mTimer.Elapsed

‘Put your code here to execute
End Sub

, ,

  1. No comments yet.
(will not be published)
Submit Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe to comments feed
  1. No trackbacks yet.

SetPageWidth