调度程序不会引发未处理的异常事件

时间:2016-03-21 09:25:33

标签: c# wpf exception exception-handling dispatcher

我遇到的情况是,Dispatcher不会引发UnhandledException事件,也不引发UnhandledExceptionFilter事件。

但根据MSDN,当Invoke中出现异常时,它会引发这些事件。

这是我最小的不工作的例子:

[Test]
public void Should_raise_unhandled_exception_event()
{
    var control = new Canvas();
    var window = new Window { Content = control };
    window.Show();
    control.Dispatcher.UnhandledExceptionFilter += (s, e) =>
    {
        Debug.WriteLine("filter unhandled exception");
        Debug.WriteLine("e.RequestCatch: {0}", e.RequestCatch);
    };
    control.Dispatcher.UnhandledException += (s, e) =>
    {
        Debug.WriteLine("unhandled exception: {0}", e.Exception);
        e.Handled = true;
    };
    control.Dispatcher.Invoke(() => { throw new ArgumentOutOfRangeException(); });
    window.Close();
}

我的所有事件处理程序都没有被调用。 我不明白为什么。有人可以解释一下吗?

0 个答案:

没有答案
相关问题