Could someone please tell me where I'm going wrong... attempting to write a Windows service and have found a few examples but none of which have worked. The following code is the best so far but stops with the following message:- (maximum points here for a quick answer)
"Service cannot be started. System.NullReferenceExcept
ion: Object reference not set to an instance of an object."
It appears to be complaining about the Timer1.Enabled line
Here's the code:-
Public Class Service1
Friend WithEvents Timer1 As System.Timers.Timer
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.
Timer1.Enabled = True
Timer1.Interval = 3000
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
Dim timer1 As New Timer
Timer1.Enabled = False
End Sub
Private Sub Timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEvent
Args) Handles Timer1.Elapsed
Beep()
End Sub
End Class
Thanks
Dave
Start Free Trial