在WPF中处理未处理的异常

时间:2016-11-08 06:15:34

标签: c# wpf

我尝试使用以下方法处理应用程序中抛出的任何未处理的异常:

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"
             >

代码:

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
}

但调度程序不工作,并且在应用程序抛出异常时不执行。

0 个答案:

没有答案
相关问题