This project has moved and is read-only. For the latest updates, please go here.

AppDomains with Multithreaded apps and MEF

Jan 19, 2010 at 6:39 PM

Good Afternoon, we are having some issues with AppDomains and MEF and cannot seem to find the answers to our questions on how MEF acts around AppDomains.  So here is the scenario:

We have a 3rd party API that allows connections to a server. Our application is a windows service that runs 4 concurrent threads to process information. The service spawns 4 seperate threads which uses MEF to load plugins that execute procedures based on various things. So we have this service which runs and autodiscovers the plugins and then passes the data through the correct plugin. Now, one of our plugins is connecting to this server through the API but the API is not smart enough to recognize the 4 threads as being different connection requests and therefore we have issues with the threads overlapping. Through discussion and testing on their part, we are told that we need to seperate the 4 threads into seperate appdomains.

So the questions we have at this point are:

  • What will MEF do when instantiated and used in another AppDomain?
  • Is it safe to share MEF parts between AppDomains?
  • Currently we are reusing the imported collection between the threads, will we need to import new objects for each AppDomain? How would we go about doing this?

We have done some preliminary testing. We created a new AppDomain and executed the method to do the compose and begin the line of processing. The method executed as expected which would indicate that the AppDomain was created successfully. We used the AppDomain.DoCallBack() method to execute (link to msdn: When we checked the executing AppDomain it was still the same as the host domain. If any help or guidance can be found, I am confident that it is here. Thanks in advance.