I have inherited a Windows service written in C#. Under rare conditions it fails badly. However, it isn\'t at all clear how to fail well. Ross Bennett states the problem e
You can get the proper ExitCode as described here. So the Windows Service Manager will give the right error text.
My OnStart in ServiceBase looks like this:
protected override void OnStart(string[] args)
{
try
{
DoStart();
}
catch (Exception exp)
{
Win32Exception w32ex = exp as Win32Exception;
if (w32ex == null)
{
w32ex = exp.InnerException as Win32Exception;
}
if (w32ex != null)
{
ExitCode = w32ex.ErrorCode;
}
Stop();
}
}