避免应用程序中模块出现异常
我正在开发一个应用程序,其中包含其他团队开发的模块,并且我使用 MEF 托管它。 问题是,当托管模块出现异常时,它会崩溃我的应用程序。
明显的解决方案是托管模块的开发团队将捕获所有异常,但它没有发生,所以我必须确保自己。
我的想法:
1)创建2个独立的GUI线程。是否可以 ?
2)将托管模块作为单独的 .exe 文件运行,但以某种方式将其托管在我的应用程序中。
任何帮助将不胜感激。
I'm developing an application that contains a module that other team develop and I'm hosting it using MEF.
the problem is that when the hosted module has an exception it collapse my application.
the obvious solution is that the develop team of the hosted module will catch all their exceptions but it's not happening so I have to ensure myself.
My ideas:
1) create 2 separated GUI threads. is it possible ?
2) run the hosted module as separated .exe file but host it somehow in my application.
Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您应该实现
Application.DispatcherUnhandledException
事件,有关详细信息,请单击 此处。完成此操作后,您应该与其他团队交谈以提高其模块的稳健性。
编辑:
或者您可以按照此方法< /a>.但我会努力提高稳健性。
Well first you should implement the
Application.DispatcherUnhandledException
event, for further details click here.After doing this you should talk to the other team to improve the robustness of their module.
EDIT:
Or you could follow this approach. But I would try to improve the robustness.
我认为最好的方法是设置一些测试来验证您使用的其他团队的模块是否适合您的目的。
除了这种明显但耗时的方法之外,您还可以将事件处理程序附加到 Application.DispatcherUnhandledException 并优雅地处理导入模块中的异常。您应该能够在事件参数的 Exception.Source 属性中找到异常的来源。
I think the best approach is to set up some tests to verify that the modules you use from the other team work for your purposes.
Apart from that obvious, but time consuming approach, you could attach an event handler to the Application.DispatcherUnhandledException and gracefully handle exceptions from your imported module. You should be able to find the source of the exception in the event args' Exception.Source property.