I have a C# WPF program using AciveX objects and providing WCF service. So there are many threads, many calls to unmanaged code. Sometimes under full load application crashes. I am investigating the problem – and it looks like problem is somewhere in ActiveX, which I can not change. Anyhow I need a way to restore program after crash. As for now I have found solution:
public partial class App : Application
{
private static readonly Logger log = LogManager.GetCurrentClassLogger();
bool isClosing = false;
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute]
void D_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
log.FatalException("Error UnhandledException ", (Exception)e.ExceptionObject);
MonitoringSvc.host.Close();
log.Info("Restarting");
if (!isClosing)
{
System.Windows.Forms.Application.Restart();
System.Windows.Application.Current.Shutdown();
}
}
private void Application_Startup(object sender, StartupEventArgs e)
{
AppDomain D = AppDomain.CurrentDomain;
D.UnhandledException += new UnhandledExceptionEventHandler(D_UnhandledException);
}
private void Application_Exit(object sender, ExitEventArgs e)
{
isClosing = true;
}
}
Program restarts on unhandled exception (on simulated for sure). But old copy stays unclosed with system message “program terminated Unexpectedly”. Program does not interact with user most time so nobody can close that message to close the program. The question is how to silently close that old windows?
Here is solution how to disable windows appearing on program crash. Not only WER, because even with WER disabled other window is shown (asking to close or debug program).