Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a c# service crash if there is a catch all

I have a service that is started using a start routine surrounded by a try catch block as below.

    protected override void OnStart(string[] args)
    {
        try
        {
            Program.Start();
        }
        catch (Exception e)
        {
            Logger.Error("Exception during Service Start");
        }
    }

Occasionally on some machines (1/100) it will occasionally print out the last line of Program.Start (a log message) and then fail with no log messages or event log messages. Should this be possible?

Thanks

EDIT: The service does kick off a few other threads but they are encapsulated in the same manner

EDIT: The Logger is a wrapper for log4net - it's working very reliably on a lot (100+) of machines (though yes it possibly the cause)

like image 479
probably at the beach Avatar asked Nov 23 '25 04:11

probably at the beach


2 Answers

The service could crash if an exception is thrown out of a started thread but not caught.

Are you adding a handler to each app domain unhandled exception?

eg:

  AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );

EDIT Also, you have the Application.ThreadException event which i forgot to mention: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx

like image 155
WraithNath Avatar answered Nov 24 '25 17:11

WraithNath


If the program crashes or an exception is thrown from try block, then for sure youll get Logger.Error log info but not the eventlog from system. If service crash or an unhandled exception occurs, then only eventlog on service is logged.

like image 42
Zenwalker Avatar answered Nov 24 '25 18:11

Zenwalker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!