Skip to main content

Posts

Showing posts with the label WP7 WP7Contrib CodePlex ObservableCollection

WP7Contrib: Thread safe ObservableCollection<T>

Continuing with the introduction of WP7Contrib concepts, patterns & services from my previous post I thought I would explain why we have chosen to implement our own ObservableCollection. As with the desktop version of Silverlight the idea of a 'blocking call' on the UI thread is discouraged, to point where if you do block the UI thread on a WP7 device your application could be automatically torn down - bad user experience. So to get round the issue the Silverlight framework makes use of the standard .Net 'async pattern' - IAsyncResult interface. Examples of this are the HttpWebRequest class and it's counterpart HttpWebResponse , they allow you to execute web requests without blocking the UI thread. The problem with the ObservableCollection<T> supplied by the framework is it's not thread safe for any methods. For example, when you have a control bound to the collection and it's enumerating over the collection and another thread modifies the coll...