title: Remove an item from an ObservableCollection in a CollectionChanged event handler
body: <p>I'm hoping to be able to reject some items after they have been added to an ObservableCollection.  I am not able to subclass the ObservableCollection or use any sort of view, so I seem to be limited to using the one event handler defined (CollectionChanged) to perform a .Remove() on the prohibited items.  It's fine if the items exist for the short period between the event being raised and then handled; the items should just not persist in the collection.  Calling .Remove() within the CollectionChanged event handler doesn't appear to be allowed.  At runtime .NET throws an InvalidOperationException:</p>
  
  <blockquote>
    <p>"Cannot change ObservableCollection during a CollectionChanged event."</p>
  </blockquote>
  
  <p>Personally I think .NET should allow me to.  If I create an infinite loop, it's my own darn fault.</p>
  
  <p>The code I would like to use would look like:</p>
  
  <pre><code>myCollection.CollectionChanged += (sender, args) =&gt;
  {
      if (args.Action == NotifyCollectionChangedAction.Remove)
          return;
      foreach (var itm in myCollection)
      {
          if (itm.name == "Fred")
              myCollection.Remove(itm);
      }
  }
  </code></pre>
  
  <p>I'm not sure what options I have.  Using a dispatcher doesn't seem to work.  Triggering another event and placing the .Remove call in another handler is the only other option that comes to mind.</p>