最近,我遇到了一个问题,我仍然不知所措.在应用程序中,我注册了一个调度程序异常处理程序.在同一个应用程序中,第三方组件(DevExpress Grid Control)会在事件处理程序中导致异常Control.LayoutUpdated.我希望,调度程序异常处理程序被触发一次.但相反,我得到了堆栈溢出.我生成了一个没有第三方组件的示例,发现它发生在每个WPF应用程序中.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
namespace MyApplication
{
/* App.xaml
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MyApplication.App"
Startup="OnStartup"
/>
*/
public partial class App
{
private void OnStartup(object sender, StartupEventArgs e)
{
DispatcherUnhandledException += OnDispatcherUnhandledException;
MainWindow = new MainWindow();
MainWindow.Show();
}
private static void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message);
e.Handled = true;
}
}
public class MainWindow : Window
{
private readonly Control mControl;
public MainWindow()
{
var grid = new Grid(); …Run Code Online (Sandbox Code Playgroud)