WindowsService Exception Handling

110 views Asked by At

I've webservice (on test machine) running as windows server. Sometimes it crashes (which is small problem).Big problem is when it crashes, there is very little information to know what happend. Smthg like this in eventviewer:

EventType clr20r3, P1 mywebservice.exe, P2 1.0.5085.19354, P3 529d9a15, P4 mscorlib, P5 2.0.0.0, P6 5040540e, P7 e2, P8 10, P9 system.invalidoperationexception, P10 NIL.

This is code which starts up process. If i try to manually throw InvalidOperationException() from various places of code, exceptions are handled.

static void Main(string[] args)
{
   try
   {
      MainLow(args);
   }
   catch (Exception ex)
   {
      Log.Error(ex);
      throw;
    }
 }
1

There are 1 answers

0
simon at rcl On

You need to trap errors in the Start method of the service class, not in Main.

Cheers -