Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可能看到来自WPF崩溃的错误消息?_C#_Wpf - Fatal编程技术网

C# 是否可能看到来自WPF崩溃的错误消息?

C# 是否可能看到来自WPF崩溃的错误消息?,c#,wpf,C#,Wpf,在编写WPF应用程序时,我经常发现在运行新功能时,它有时会关闭,通常不会出现错误消息。这会使调试变得很有挑战性,因为我通常必须猜测和实验代码才能找到错误。是否可能看到类似控制台输出的错误消息之类的错误消息,它是否涉及输出窗口?您可以通过在App.xaml中添加DispatcherUnhandleException来捕获异常 请显示此“特定函数”。使用调试器F5。它将在引发异常的线路上中断,导致应用程序崩溃,并显示异常消息。谢谢@BionicCode,这正是我要找的!对不起,这个问题问得不好。 &

在编写WPF应用程序时,我经常发现在运行新功能时,它有时会关闭,通常不会出现错误消息。这会使调试变得很有挑战性,因为我通常必须猜测和实验代码才能找到错误。是否可能看到类似控制台输出的错误消息之类的错误消息,它是否涉及输出窗口?

您可以通过在App.xaml中添加DispatcherUnhandleException来捕获异常


请显示此“特定函数”。使用调试器F5。它将在引发异常的线路上中断,导致应用程序崩溃,并显示异常消息。谢谢@BionicCode,这正是我要找的!对不起,这个问题问得不好。
<Application x:Class="Organizer.UI.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Organizer.UI"
             xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
             Startup="Application_Startup"
             DispatcherUnhandledException="Application_DispatcherUnhandledException">
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
    MessageBox.Show("Error" + Environment.NewLine + e.Exception.Message, "Error");
    e.Handled = true;
}