我的应用程序是建立在WPF,但它包含一些我们写的WinForms组件。当一个例外是在未处理的WinForms的组件崩溃的应用程序之一。
我已实施 DispatcherUnhandledException
为WPF事件。这是好事,因为它可以让我的处理,以避免崩溃显示错误并标记异常。
我可以做非WPF异常类似的东西。我希望的是用来上来,并允许用户继续还是蛮应用标准的WinForms对话框?
修改:WinForms的例外也陷入 DispatcherUnhandledException
,但设置e.Handled为true不会崩溃停止应用程序
解决方案
您是否尝试过System.Windows.Forms.Application.ThreadException和System.Windows.Forms.Application.SetUnhandledExceptionMode ?
My application is built in WPF but it includes some WinForms components that we have written. When an exception is unhandled in one of the WinForms components it crashes the application.
I have implemented DispatcherUnhandledException
for WPF events. This is good because it allows me to display an error and mark the exception as Handled to avoid the crash.
Can I do something similar with the non-WPF exceptions. I was hoping for the standard WinForms dialog that used to come up and allow the user to continue or quite the application?
Edit: WinForms exceptions do get caught in DispatcherUnhandledException
but setting e.Handled to true doesn't stop the application from crashing.
Have you tried System.Windows.Forms.Application.ThreadException and System.Windows.Forms.Application.SetUnhandledExceptionMode ?