3

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.

enter image description here

H.B.
  • 166,899
  • 29
  • 327
  • 400
Erez
  • 6,405
  • 14
  • 70
  • 124

2 Answers2

0

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.

jjrdk
  • 1,882
  • 15
  • 18
0

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.

Community
  • 1
  • 1
DHN
  • 4,807
  • 3
  • 31
  • 45
  • thanks but DispatcherUnhandledException handles only exception that are in Gui thread and not those in the background thread. (which is good for the most of the exception but not for all of them) – Erez Mar 03 '11 at 09:25
  • Well then follow my second advice. It should not be your task to handle exceptions of threads, which are started in another modules. If you keep working around such problems you will face probably some serious problems in a few months. Don't cure the symptom, eliminate the reason! – DHN Mar 03 '11 at 09:31