views:

27

answers:

1

This may come off as a totally n00b question as I know very little about PRISM at all yet, but let's imagine I have a hypothetical situation of a composite application consisting of 3 controls: Control A (a chart), Control B (a table) and Control C (a calculator).

Are all of these controls running on the same UI thread? For example if Control A starting doing some crazy calculation on it's main thread and was blocking - would the entire container freeze?

If the answer to this question is yes - is the only solution to tell the "control team" for A not to do that? Or is there some design pattern we could think about to handle it?

If the answer to this question is no - can you explain a bit how this works or point me at some documentation I could review on the subject?

Thanks

+2  A: 

WPF uses a Dispatcher thread to synchronize UI access, so yes essentually they would all be running on the same thread. You can still implement asynchronous calls in the usual way, but to update the UI you need to rejoin the Dispatcher thread using the Dispatcher:

if (!Dispatcher.CheckAccess())
   Dispatcher.Invoke(new Action(() => item.Items.Add(subitem)));
else
   item.Items.Add(subitem);

You can also do this when using the EventAggregator to subscribe to events as follows:

 eventAggregator.GetEvent<AnEvent>().Subscribe(DoWork, ThreadOption.UIThread);

There's some more info here on the subject:

http://msdn.microsoft.com/en-us/library/ms741870.aspx#threading_overview

TheCodeKing