title: What is the correct usage of ConcurrentBag?
body: <p>I've already read previous questions here about <code>ConcurrentBag</code> but did not find an actual sample of implementation in multi-threading.</p>
  
  <blockquote>
    <p>ConcurrentBag is a thread-safe bag implementation, optimized for scenarios where the same thread will be both producing and consuming data stored in the bag."</p>
  </blockquote>
  
  <p>Currently this is the current usage in my code (this is simplified not actual codes):</p>
  
  <pre><code>private void MyMethod()
  {
      List&lt;Product&gt; products = GetAllProducts(); // Get list of products
      ConcurrentBag&lt;Product&gt; myBag = new ConcurrentBag&lt;Product&gt;();
  
      //products were simply added here in the ConcurrentBag to simplify the code
      //actual code process each product before adding in the bag
      Parallel.ForEach(
                  products,
                  new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount },
                  product =&gt; myBag.Add(product));
  
      ProcessBag(myBag); // method to process each items in the concurrentbag
  }
  </code></pre>
  
  <p>My questions:<br>
  Is this the right usage of <code>ConcurrentBag</code>? Is it ok to use <code>ConcurrentBag</code> in this kind of scenario?</p>
  
  <p>For me I think a simple <code>List&lt;Product&gt;</code> and a manual lock will do better. The reason for this is that the scenario above already breaks the "<strong>same thread will be both producing and consuming data stored in the bag</strong>" rule.<br>
  Also I also found out that the <code>ThreadLocal</code> storage created in each thread in the parallel will still exist after the operation (even if the thread is reused is this right?) which may cause an undesired memory leak.<br>
  Am I right in this one guys? Or a simple clear or empty method to remove the items in the <code>ConcurrentBag</code> is enough?  </p>