title: Implement Parallel.Foreach inside a while loop
body: <p>I have scenario where I need to run a Parallel.Foreach within a while loop. I need to understand the impact of this implementation in terms of how the processing will take place. I will have an implementation something like this</p>
  
  <pre><code> ConcurrentQueue&lt;MyTable&gt; queue = new ConcurrentQueue&lt;MyTable&gt;();
  </code></pre>
  
  <p>Here, I have initially added lot of items in queue but while execution also, more items can be added in the queue.</p>
  
  <pre><code>while(true)
  {
      Parallel.Foreach(queue, (myTable) =&gt; {some processing});
      Sleep(sometime);
  }
  </code></pre>
  
  <p>Each time one item will be de-queued and new thread will be spawned to work with it, in the meanwhile new items will be added for that I need to keep an infinite while loop. </p>
  
  <p>Now, I need to understand that as concurrent queue is thread safe, I think each item will be processed one time only in spite of while above foreach but I am not sure about is that there will be multiple threads of foreach itself that will be spawning child threads or single copy of foreach will be running within while loop. I do not know how foreach itself is implemented.</p>