Advertisement

01.15.2007 at 02:47AM PST, ID: 22122763
[x]
Attachment Details

Writing a Windows Service problem

Asked by dmarch100 in Microsoft Visual Basic.Net

Tags: service, beep, new, window

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.NullReferenceException: 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.ElapsedEventArgs) Handles Timer1.Elapsed
    Beep()
  End Sub
End Class

Thanks

DaveStart Free Trial
[+][-]01.15.2007 at 02:52AM PST, ID: 18315449

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.15.2007 at 02:53AM PST, ID: 18315450

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.15.2007 at 02:54AM PST, ID: 18315458

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: service, beep, new, window
Sign Up Now!
Solution Provided By: Kinger247
Participating Experts: 1
Solution Grade: A
 
 
[+][-]01.15.2007 at 03:22AM PST, ID: 18315555

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.15.2007 at 03:28AM PST, ID: 18315579

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32