C
C#

help

WPF Handling crashes more gracefully. [Answered]

DDoombox8/24/2022
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();
}
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();
}
RRazorSharpFang8/24/2022
When you say Window do you mean that MessageBox ?
DDoombox8/24/2022
nope the application window itself, the messagebox closes correctly
RRazorSharpFang8/24/2022
You could loop through all the Application Windows and Hide them
DDoombox8/24/2022
I tried to grab the window from my IoC container and call .Close() but that didn't seem to work just caused the UI to lockup at a different point
RRazorSharpFang8/24/2022
Nono, Hide, not close
DDoombox8/24/2022
ah hide works, that's weird, thanks! I guess Close tries to call/access stuff that is unavailable whilst the app is crashing
RRazorSharpFang8/24/2022
A closed window cannot be reopened A hidden window can be shown again
AAccord8/24/2022
✅ This post has been marked as answered!

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ Should a beginner at webdev learn React or Angular for the frontend to go with ASP.NET?I know that React is a little more popular than Angular overall, but i'm not sure what it's like forHow can I sort a list of entries (Id, ParentId) into a tree hierarchy? [Answered]I have an unsorted list of entries with two notable fields: `Id` and `ParentId`. I would like to sorNeed Help with creating a JsonSchemaI need to create a JSON-Schema to validate some properties of a json object. I'm using the `oneOf` pError Handling vs Type Enforcement [Answered]In what scenarios would error handling be more effective/efficient and in what scenarios would only Hosting an APIWhat would you guys use to host a websocket stream API such as https://docs.deribit.com/ or https://WPF InputBinding with Mouse4 or Mouse5 (X1 or X2)MouseBinding only seems to support Left, middle and right clicking (and the double click versions) (App.Config vs Resources.resx [Answered]What's the main difference between them also why App.Config considered more secure approach ? 2nd quUsing multiple RateLimiters correctly. [Answered]I'm wrapping an API which requires no more than 4 requests per second **and** 200 per hour, I've gotAbstract List of KeyValuePairs```cs public abstract List<KeyValuePair<string, int>> inventory;``` It says I can't do this with a fMAUI navigation to new page with injected viewModelIf you think this belong more into #mobile channel I can move, but I think some of you who are morecatching an exception in an async Task [Answered]I can't seem to catch an exception that is thrown in an async Task, I put try/catch within the asyncpass data onclick from one page to another page in asp nethi all, im trying to redirect a page from **Main Page** to **Sub Page** when i click an item on **MASP NET Core default DI-Container, how pass in constructor not-registered parameter? [Answered]I want to create a Model class using a DI container, services registered in the container are passedShould I return the whole created object in POST or just return the id of that object ?When I creating a post method I find myself repeat what I did in GetById Should I just return the Iasp net cshtml javascript filehi all, i have an asp net project (SimpleApp) and in a cshtml file of my **SimpleApp ** project i trChange Visual Studio suggetions with custom analysersHiya.. ohh discords new "forum" channels are super useful for this huh?. anyway. So I managed to impNullReferenceException Object reference not set to an instance of an object```cs List<Effects> effectsList = activePlayerEffects[targetPlayer] ?? new List<Effects>(); ``` someDbContext.SaveChangesAsync has no effect on the collection of changed objectsHi. I get products collection from dbContext, change some values and want to save it in the databaseWindowsIdentity claims don't include all AD attributes, how do I fix that?I'm using windows authentication and want to display a user's full name, however on inspection the ihow to create a jwt for an existing user in identityI am looking to create a new JWT and validate it... for using tiwht signalr. so i want to know how t