MEF, High Performance Application (multi threaded, multiple window threads)

Oct 13, 2009 at 7:14 PM

Hello,

just a question - how thread safe is MEF?

I am tasked writhing a high performance visualization framework. The application will be modular (allowing generated visualizations to hook in). It requires a lot of processing power, though, so it will have multiple windows (allowing it to run on multiple screens), and every window will have it's own message pump.

This basically means that when one window is working (setting things up etc.), another window may ask for components in another thread.

Anything I should be aware of? MEF thread-safe enough for that, or will I have to route certain things into one main user interface thread? The intial setup of the application is single threaded - right until the main thread moves into the control window message loop ;) Then through it's menues (and loading an existing layout) multiple windows can be created.

Obviously this means that when I do things like refreshing the catalog..... or asking for new instances..... this may happen on multiple threads.

Problems to be expected? What should I be watching out for?

Oct 13, 2009 at 8:13 PM

Hi ttomiczek

In Preview 7 we added better threading support for MEF. The container contains a constructor parameter you should set to have it created in a thread-safe mode.  Once in that mode, the container can be accessed by multiple threads in the manner you described.

The one caveat is that composition must occur on a single thread and cannot jump threads. HTH

Glenn

Oct 13, 2009 at 8:16 PM

Hi Glenn,

can you get me a little more on the single thread limit?

My concept would be:

* Initialisnig the system on the main control thread (i.e. the main UI window thread in fact). All new windows are generated from there, too.

* Sub-windows (separate threads) would get called on their own thread with the creation of exported elements. This would all happen on their own thread.

Would that work and be wthin the one thread limit?

Oct 13, 2009 at 8:34 PM

What this mean is within a single composition the container cannot jump threads. If what you are doing is spawning new windows in different threads, that have their own compositions, I would consider spawning hierarchical containers off of the main thread. Each container can then compose on it's own thread safely and still access services from the main container.

Glenn