Concurrency, WinRT ObservableCollection and Iteration

Monday, January 14, 2013

You can download the source-code from https://github.com/tamirdresher/WinRTThreadSafeObservableCollection Today I want to discuss a problem I faced in a WinRT project I'm working on The short story: We receive events from the network on a background thread(s) The events bubble up to the UI layer and caught in the ViewModel The ViewModel changes an inner ObservableCollection in response to the event One thread is adding\removing from the collection while another searches for an element in it. The search is iterating a collection that is being modified è Exception is thrown  The solution to the problem is one of two: Making a lock mechanisem on the collection...