title: How to call a function when a collection contains n elements after an addition of element?
body: <p>I am writing some concurrent program that finds improvements on a planning. Multiple threads search for improvements in the planning. When they find one, they add the improvement to a <code>ConcurrentBag</code>. When there are <em>n</em> improvements in the <code>ConcurrentBag</code>, a function should be called that processes all improvements and tells all threads to update their working planning.</p>
  
  <p>Do I have to override the <code>ConcurrentBag</code> and change its <code>.Add</code> function into something like:</p>
  
  <pre><code>Add(Item item)
  {
      base.Add(item);
      if (this.Count() &gt; n) SomeStaticClass.ProcessImprovements();
  }
  </code></pre>
  
  <p>or is there a better option? Overriding a class for this seems unnecessary to me, but I don't know any better way of doing it.</p>
  
  <p>Is there maby some listener structure or something? Who can help me or point me in the right direction?</p>