Error during start of Windows Service...

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Got another question on my Windows Service which I coded in
VB.NET. During the OnStart event (when the service is
started) I set up a database connection that my service
uses. Let's say something occurs during the middle of this
- or any other error - which would cause my service to NOT
start up. How should one handle that? Obviously, using a
Try...Catch - but my question deals with how to tell the
Windows Service Manager that the service didn't start? On
some events you have an e.Cancel or such to say that
validation didn't work - was wondering if there was
something like that for a service.

If, for instance, I catch an error in my OnStart method,
what do I do then to tell the Service Manager my service
didn't start up correctly? I wouldn't want the Service
Manager to say my service is running when in fact it got an
error and I caught it but couldn't continue.

Hope this makes sense. Thanks in advance.

Tom

--
 
Tom said:
Got another question on my Windows Service which I coded in
VB.NET. During the OnStart event (when the service is
started) I set up a database connection that my service
uses. Let's say something occurs during the middle of this
- or any other error - which would cause my service to NOT
start up. How should one handle that? Obviously, using a
Try...Catch - but my question deals with how to tell the
Windows Service Manager that the service didn't start? On
some events you have an e.Cancel or such to say that
validation didn't work - was wondering if there was
something like that for a service.

If, for instance, I catch an error in my OnStart method,
what do I do then to tell the Service Manager my service
didn't start up correctly? I wouldn't want the Service
Manager to say my service is running when in fact it got an
error and I caught it but couldn't continue.

Hope this makes sense. Thanks in advance.

Tom
Just throw an exception, this will return to the SCM who will post a message
into the application eventlog and terminate your service.

Willy.
 
Back
Top