WPF MVVM updating the View Model on a Background Worker?

This sounds ok. As long as your item-object is no DependencyObject you can change the properties of them in the background worker DataBinding to properties of your object will work, the binding engine will do the thread-switching automatically for you However, dont't fill data-bound collections or manipulate properties of DependencyObjects (such as UI-Controls) in the background worker without dispatching the manipulations. This would lead to an exception.

This sounds ok. As long as your item-object is no DependencyObject, you can change the properties of them in the background worker. DataBinding to properties of your object will work, the binding engine will do the thread-switching automatically for you.

However, dont't fill data-bound collections or manipulate properties of DependencyObjects (such as UI-Controls) in the background worker without dispatching the manipulations. This would lead to an exception. Edit: Only for clarification: The real question is not, if the item-object is a DependencyObject but if the property is a CLR-property or a DependencyProperty.

Because DependencyProperties are bound to DependencyObjects, I often use the above simplification, but its not the full truth. This means that if you have a CLR-property, you can set its value from a foreign thread, regardless of your class is a DepenendencyObject or not. This is a slight difference to my first statement.

WOW, super fast reply thanks. Can you explain what you mean by Dispatching the manipulations? – Tim Mar 4 at 16:35 @Tim: Sorry my english.

I mean invoking the operation with the Dispatcher of the UI-Thread. The dispatcher will schedule the execution of the operation in the right (UI) thread. Msdn.microsoft.Com/en-us/library/… – HCL Mar 4 at 16:44 Thanks, just run a test and indeed I do get an error.

Will investigate. – Tim Mar 4 at 17:08 found this article seems to do the job! Michlg.wordpress.Com/2009/08/14/… – Tim Mar 4 at 17:26 Dispatching means you have to wirte something like that in your backgroundworker: Application.Current.Dispatcher.

BeginInvoke(new Action(() => ...here goes what ever you want to do in the ui thread...)); – blindmeis Mar 47 at 13:11.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions