Sometimes, under not reproducible circumstances, my WPF application crashes without any message. The application simply close instantly.
Where is the best place to implement the global Try/Catch block. At least I have to implement a messagebox with: "Sorry for the inconvenience ..."
You can trap unhandled exceptions at different levels:
AppDomain.CurrentDomain.UnhandledException
From all threads in the AppDomain.Dispatcher.UnhandledException
From a single specific UI dispatcher thread.Application.Current.DispatcherUnhandledException
From the main UI dispatcher thread in your WPF application.TaskScheduler.UnobservedTaskException
from within each AppDomain that uses a task scheduler for asynchronous operations.You should consider what level you need to trap unhandled exceptions at.
Deciding between #2 and #3 depends upon whether you're using more than one WPF thread. This is quite an exotic situation and if you're unsure whether you are or not, then it's most likely that you're not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With