title: While using ConcurrentQueue, trying to dequeue while looping through in parallel
body: <p>I am using the parallel data structures in my .NET 4 application and I have a <code>ConcurrentQueue</code> that gets added to while I am processing through it.</p>
  
  <p>I want to do something like:</p>
  
  <p><code>personqueue.AsParallel().WithDegreeOfParallelism(20).ForAll(i =&gt; ... );</code></p>
  
  <p>as I make database calls to save the data, so I am limiting the number of concurrent threads.</p>
  
  <p>But, I expect that the <code>ForAll</code> isn't going to dequeue, and I am concerned about just doing</p>
  
  <pre><code>ForAll(i =&gt; {
      personqueue.personqueue.TryDequeue(...);
      ...
  });
  </code></pre>
  
  <p>as there is no guarantee that I am popping off the correct one.</p>
  
  <p>So, how can I iterate through the collection and dequeue, in a parallel fashion.</p>
  
  <p>Or, would it be better to use <code>PLINQ</code> to do this processing, in parallel?</p>