Gracefully fail to start a service

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
 
N

Nick Holmes

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top