title: WPF Collections synchronization misbehavior
body: <p>In my WPF/MVVM application I make heavy use of collections which are bound through DataBinding to my views. These shall be sync-ed through</p>
  <pre><code>BindingOperations.EnableCollectionSynchronization(Collection, _collectionLock);
  </code></pre>
  <p>placed in the constructor, so that when I receive an update notification I should not get any exception.
  This is the code which performs the collection update:</p>
  <pre><code>private void MyCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
      {
          switch (e.Action)
          {
              case NotifyCollectionChangedAction.Add:
                  foreach (var item in e.NewItems)
                  {
                      var newItem = new ItemViewModel(item as DataTypes.Item);
                      newItem.PropertyChanged += itemsCollection_PropertyChanged;
  
                      Collection.Add(newItem);
                  }
                  break;
  
              case NotifyCollectionChangedAction.Remove:
                  foreach (var item in e.OldItems)
                  {
                      Collection.Remove(Collection.First(x =&gt; x.Name == (item as DataTypes.Item).Name));
                  }
                  break;
  
              //Reset = Clear
              case NotifyCollectionChangedAction.Reset:
                  Collection.Clear();
                  break;
          }
      }
  </code></pre>
  <p>Problem is that even if it is synchronized as shown, I still receive the following Exception:</p>
  <blockquote>
  <p>A first chance exception of type 'System.NotSupportedException' occurred in PresentationFramework.dll.</p>
  <p>An unhandled exception of type 'System.NotSupportedException' occurred in PresentationFramework.dll</p>
  <p>Additional information: This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.</p>
  </blockquote>
  <p>I tried different ways but still getting this error; the only way is to update the collection through a Dispatcher call but it seems to me this would be superfluous due to the Collection being synced.</p>
  <p>EDIT: it seems that I'm getting the Exception even when invoked from a Dispatcher call, and that's seems an even worse behavior to me.</p>
  <pre><code>Application.Current.Dispatcher.Invoke(new Action(() =&gt;
  {
      Collection.Add(newItem);
  }));
  </code></pre>