title: How to safely call Count(Func) on an IEnumerable that can be changed by another thread?
body: <p>One of my WPF element is data-bound to a property that calls <code>Count(Func)</code> on a <code>IEnumerable</code>. The property displays something like the count of active entities in the system (thus the need of a <code>Func</code> parameter). </p>
  
  <pre><code>public int ActiveEntitiesCount
  {
      get
      {
          return Entities.Count((item) =&gt;
          {
              //my own code, just a couple of value comparisons, very quick
          });
      }
  }
  </code></pre>
  
  <p>.
  However the <code>IEnumerable</code> is a list that can be changed by another thread at any time. Sometimes, the application crashes, apparently because the <code>IEnumerable</code> is modified while the <code>Count</code> function enumeration is in progress.</p>
  
  <p>I can put a <code>try-catch</code> block, but how to get the value to be returned by that property?</p>
  
  <p>Note: Using lock may be not practical, because I don't know all the codes that's accessing the <code>IEnumerable</code></p>