I'm trying to handle any unhandled exception thrown in the application using this:
The xaml:
<Application x:Class="Updater.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ShutdownMode="OnExplicitShutdown"
DispatcherUnhandledException="UnhandledException"
>
The code:
private void UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var time = DateTime.Now;
File.AppendAllText(@"C:\exps.csv", string.Format("{0},{1}", time, e.Exception.Message));
File.AppendAllText(@"C:\sts.txt", time + ":\n" + e.Exception.StackTrace + "\n");
e.Handled = false; //we want the user to experience the crash
}
But the dispatcher not working and not execute when the application throw exception.