title: Is there a Threadsafe Observable collection in .NET 4?
body: <p>Platform: <code>WPF, .NET 4.0, C# 4.0</code></p>
  
  <p>Problem: In the Mainwindow.xaml i have a ListBox bound to a Customer collection which is currently an ObservableCollection&lt; Customer >.</p>
  
  <p><code>ObservableCollection&lt;Customer&gt; c = new ObservableCollection&lt;Customer&gt;();</code></p>
  
  <p>This collection can be updated via multiple sources, like FileSystem, WebService etc.</p>
  
  <p>To allow parallel loading of Customers I have created a helper class </p>
  
  <p><code>public class CustomerManager(ref ObsevableCollection&lt;Customer&gt; cust)</code></p>
  
  <p>that internally spawns a new Task (from Parallel extensions library) for each customer Source and adds a new Customer instance to the customer collection object (passed by ref to its ctor).</p>
  
  <p>The problem is that ObservableCollection&lt; T> (or any collection for that matter) cannot be used from calls other than the UI thread and an exception is encountered:</p>
  
  <p>"NotSupportedException – This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread."</p>
  
  <p>I tried using the </p>
  
  <p><code>System.Collections.Concurrent.ConcurrentBag&lt;Customer&gt;</code> </p>
  
  <p>collection but it doesnot implement INotifyCollectionChanged interface. Hence my WPF UI won't get updated automatically.</p>
  
  <p><strong>So, is there a collection class that implements both property/collection change notifications and also allows calls from other non-UI threads?</strong></p>
  
  <p>By my initial bing/googling, there is none provided out of the box.</p>
  
  <p>Edit: I created my own collection that inherits from <em>ConcurrentBag&lt; Customer ></em> and also implements the <em>INotifyCollectionChanged</em> interface. But to my surprise even after invoking it in separate tasks, the WPF UI hangs until the task is completed. <strong>Aren't the tasks supposed to be executed in parallel and not block the UI thread</strong>?</p>
  
  <p>Thanks for any suggestions, in advance.</p>