C# 尝试在DispatcherUnhandledException上显示对话框

C# 尝试在DispatcherUnhandledException上显示对话框,c#,wpf,C#,Wpf,我有一个WPF应用程序,我在其中添加了一些顶级的、全面的错误处理。我处理DispatcherUnhandledException事件的方式如下: private void App_OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { if (_isHandlingError) { _log.Error(

我有一个WPF应用程序,我在其中添加了一些顶级的、全面的错误处理。我处理DispatcherUnhandledException事件的方式如下:

    private void App_OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
        if (_isHandlingError)
        {
            _log.Error("Critical unhandled error", e.Exception);
            e.Handled = true;
            return;
        }

        _isHandlingError = true;
        var vm = _windsorContainer.Resolve<ErrorReporterViewModel>();

        Dispatcher.Invoke(() =>
        {
            vm.Details = FailureMessageBuilder.CreateContent(e.Exception);
            var view = new ErrorReporterView { DataContext = vm };

            view.Show();
        });

        e.Handled = true;

        NotifyOfException(e.Exception, vm.Description);

        _isHandlingError = false;
    }
private void App\u OnDispatcherUnhandledException(对象发送方,DispatcherUnhandledExceptionEventArgs e)
{
如果(_isHandlingError)
{
_日志错误(“严重未处理错误”,例如异常);
e、 已处理=正确;
返回;
}
_isHandlingError=true;
var vm=_windsorContainer.Resolve();
Dispatcher.Invoke(()=>
{
vm.Details=FailureMessageBuilder.CreateContent(e.Exception);
var view=newerrorreporterview{DataContext=vm};
view.Show();
});
e、 已处理=正确;
异常通知(例如异常、虚拟机描述);
_isHandlingError=false;
}
问题是,对Show()(或ShowDialog)的调用永远不会返回,错误对话框也永远不会显示


可能是什么问题?

您是否已将事件附加到应用程序

cApp.Dispatcher.UnhandledException += new DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);
                cApp.InitializeComponent();
                cApp.Run(new MainWindow());
然后

private static void Dispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
...e.Exception.Message
}

你调试过吗?可能没有..我注意到的大多数人甚至不知道如何使用调试器。。这是一个多么滑稽的事情……只是澄清一下——事件触发,处理程序被调用。但是对Show的调用永远不会返回;然后验证它是否有效。只是澄清一下-事件触发,处理程序被调用。但要求展示的呼声从未回响。