Windows Service startup failure

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there

I've written a windows service that works OK, apart fom the fact that if it were to fail during startup, I'm not sure of the best way to handle it. If I let the exception fall thru' from my OnStart() method, the exception is reported in the event log and the service is not marked as started. But the exception message is messy and I want to catch it and report it cleanly if I can. If I catch it myself, report it then continue (without re-throwing), the service is marked as started, which isn't what I want.

Is there any way I can catch the exception for reporting myself, then indicate to the SCM that it hasn't started, without relying on 'fall through' exceptions to inidictate this?

Thanks

Jon
 
You should be able to catch the exception in your OnStart method, process
accordingly, and then throw the same exception or a new less messy exception
for the SCM to deal with.

Jon said:
Hi there

I've written a windows service that works OK, apart fom the fact that if
it were to fail during startup, I'm not sure of the best way to handle it.
If I let the exception fall thru' from my OnStart() method, the exception is
reported in the event log and the service is not marked as started. But the
exception message is messy and I want to catch it and report it cleanly if I
can. If I catch it myself, report it then continue (without re-throwing),
the service is marked as started, which isn't what I want.
Is there any way I can catch the exception for reporting myself, then
indicate to the SCM that it hasn't started, without relying on 'fall
through' exceptions to inidictate this?
 
Back
Top