I've read in this post that to avoid the “program stopped working” dialog ,I need to catch the unhandled exception from the AppDomain.
public Form1()
{
///Code
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
///more code
}
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var excep = e.ExceptionObject;
//Writing the exception to log file with the stack flow
Logger.Logger.LogException("UNHANDLED EXCEPTION:"+Environment.NewLine +excep.ToString(), this);
//Terminate the logger (manual event waiting for file write to finish)
Logger.Logger.Terminate();
Environment.Exit(1);
}
But when I get inhaled exception. I can see it written on the log, but The application shows the “program stopped working” dialog.
can it be caused by the Logger.Terminate
line?
(again - the terminate command waits until all logs were written to the log file)