Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INotifyPropertyChanged: what happens behind the scene?

In WPF we have two threads (at least): rendering and a UI thread. When I raise an event OnNotifyPropertyChanged on some property changes, it is raised on the UI thread. This information needs to be dispatched to WPF rendering thread for re-rendering. I am assuming it is done in a synchronous manner ( Dispatcher.Invoke ) but how does it really work?

If I raise multiple OnNotifyPropertyChanged events for the same data structure without locking access to the accessor property for this data structure for which these events have been raised, am I creating a potential race condition? I have seen the infamous "Collection was modified; enumeration operation may not execute" exception coming from WPF, so it looks like WPF processes these events asynchronously. Am I misunderstanding the exception? Thanks!

like image 997
Lenik Avatar asked Sep 04 '10 01:09

Lenik


1 Answers

The exception "Collection was modified; enumeration operation may not execute" is not related to WPF, it is raised from IEnumerator when you iterated on a collection with foreach and while doing that the collection is somehow changed (add/remove/modify). (e.g: http://social.msdn.microsoft.com/forums/en/netfxbcl/thread/7ce02724-2813-4f7d-8f3c-b1e3c1fd3019/) .

Other than that I have never encountered exception caused by multiple simultaneous invokes on PropertyChanged event.

like image 69
Captain Avatar answered Sep 27 '22 02:09

Captain