Gracefully fail to start a service

  • Thread starter Thread starter Joel Lyons
  • Start date Start date
J

Joel Lyons

If my service fails to start, I'd like to notify the user and either display
an error or direct them to check the event log to see more info. With
Win32, you could return a non-0 number to the SCM during startup and a
dialog would be displayed (by the SCM) showing the error number and
directing the user to check the error log for further information.

Is there similar functionality in .NET? I've tried throwing exceptions and
calling Environment.Exit([some number]) in OnStart(), but both cause the SCM
to display some useless dialog.

How are you guys handling this?
-Joel
 
Having the service display a message its very tricky, because (typically)
services are started on an different Windows Station than the one hooked up
to the monitor and keyboard. Even if you do put up a message box, you one
will see it (and perhaps worse, no one can respond to it).

Logging an error message and throwing an exception is your best bet. Yes,
the message is not good (it implies that there might *not* be a problem).

Nick.
 
Back
Top