C#C
C#4y ago
Doombox

WPF Handling crashes more gracefully. [Answered]

I'm currently using this setup which correctly logs and displays feedback correctly, however after the messagebox is closed the application window hangs around for a few seconds completely locked up, calling .Dispose() to clean up the NotifyIcon in the tray more than doubles the time. Is there a way to force the window closed?

private bool _hasProvidedCrashFeedback;

private void CurrentDomainOnFirstChanceException(object sender, FirstChanceExceptionEventArgs e) =>
    HandleException(e.Exception);

protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e) =>
    HandleException(e.Exception);

private void HandleException(Exception e)
{
    _log.Fatal(e, "");
    if (_hasProvidedCrashFeedback) return;
    _hasProvidedCrashFeedback = true;
    Dispose(); // this call doubles the time the window hangs around
    MessageBox.Show("See C:\\Users\\USERNAME\\AppData\\Roaming\\F1Desktop\\Logs for technical information.", 
        "F1 Desktop Has Crashed Unexpectedly");
}

public override void Dispose()
{
    GC.SuppressFinalize(this);
    _icon.Dispose();
    JobManager.Stop();
    base.Dispose();
}
Was this page helpful?