我在VS2008中启动了一个新的WPF项目,然后添加了一些代码来捕获DispatcherUnhandledException
。然后我给Window1
添加了一个抛出异常,但错误并未被处理程序捕获。为什么?WPF - DispatcherUnhandledException似乎不起作用
public App()
{
this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
}
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
System.Windows.MessageBox.Show(string.Format("An error occured: {0}", e.Exception.Message), "Error");
e.Handled = true;
}
void Window1_MouseDown(object sender, MouseButtonEventArgs e)
{
throw new NotImplementedException();
}
除了列表中的代码在主UI线程上抛出异常。 – svick 2011-07-22 08:59:24