首页 文章

WPF Windows窗体错误处理

提问于
浏览
1

我有一个在Windows Forms中制作的项目,所以我必须逐渐将其迁移到WPF;我已将所有表单/类复制到一个新的WPF项目中 .

一切都运行得很好,但每当我尝试捕获从[Windows窗体]表单生成的异常时, DispatcherUnhandledException 事件就无法捕获它 .

如何将[Windows窗体]表单中的所有异常捕获到 Application.DispatcherUnhandledException 事件中?

Edit 1:
我正在使用应用程序事件来处理 DispatcherUnhandledException 如果我在事件代码上放置一个断点,它就不会一步一步 .
我'm handling the exceptions is the same as all my WPF applications, then only thing that makes this project different it'包含[Windows窗体]表单的方式 . When I throw exception from a WPF window it works perfectly, but when I do it on [Windows Forms] form doesn't works.

谢谢你的建议 .

1 回答

  • 0

    看起来很奇怪 . 如果您使用MVVM,则所有应用程序错误都在ViewModel中,并且可以通过try..catch轻松捕获 . 如果不是MVVVM,只需将try catch添加到代码隐藏类中的每个方法 .

相关问题