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

Question and Suggestion regarding hadling the Dispatcher

Jan 16, 2013 at 2:20 PM


I found this very interesting article which explains how to avoid cross thread checks by creating a singleton Dispatcher to replace the normal .Net Dispatcher. A great use for it would be when using INotifyPropertyChanged (call this Dispatcher in the background instead of the normal one).

I've implemented this already in a project constructed using MVVM and it works great.

I know MVVM Light has its own implementation of PropertyChanged - my question is: could this dispatcher be integrated into MVVM Light and deployed in the release DLLs to replace all normal .Net Dispatcher calls?

I'm planning on grabbing the source code for MVVM Light and doing this myself, rebuild and use the modified DLLs, but there's a high probability I might just break something and I won't be able to benefit from normal updates...

Please consider adding support for a unified Dispatcher :)



Jan 17, 2013 at 4:06 AM

Hi Dragos,

Aside from the Dispatcher, there's another platform-agnostic way of doing something similar- SynchronizationContext. Assuming you create your object on the UI thread, simply store a reference to SychronizationContext.Current in your constructor.

I'm not sure it's always a good idea for the ViewModelBase to invoke propertychanged events on a UI thread as it's not always necessary and could lead to race conditions or other side-effects.

Generally, it's better for the class that is interacting with a background thread to do its own thread marshaling and locking to ensure it remains in control.