我对 WPF 很陌生,从 app.xaml.cs Dispatch Unhandled Exception 事件重定向到新窗口时遇到了一些问题。
基本上,我试图模仿 Web 应用程序处理错误的方式
- 错误被困
- 通过 Elmah 记录错误
- 错误通过 Elmah 通过电子邮件发送
- 如果日志记录/电子邮件成功,用户将被重定向到错误页面,否则将不处理错误
我打电话的代码是 -
private void Application_DispatcherUnhandledException(object sender,
System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
..... Processing Code
NavigationService svc = NavigationService.GetNavigationService(this);
svc.Navigate(new DIEM.WindowsApps.DIEMWindows.ErrorWindow());
}
我遇到的问题是,当调用 NavigationService.GetNavigationService(this) 时,'this' 为空(可能是因为 App.xaml.cs 不是页面,它继承自 Application)。
有没有办法解决?我做的事情完全错了吗?!
提前致谢。