static void HandleUnhandledException(object sender, UnhandledExceptionEventArgs args) { Exception e = (Exception)args.ExceptionObject; LogFile.Log("Exiting due to unhandled exception: " + e.Message); LogFile.Log(e.StackTrace); LogFile.Close(); LogCrash(e, true); try { CrashWindow crashWindow = new CrashWindow(app.MainWindow, new CrashWindowViewModel(e)); crashWindow.ShowDialog(); } catch { // hide any problems showing the crash window, but wait 5 seconds to give the crash log a chance to upload Thread.Sleep(5000); } System.Environment.Exit(0); }