title: Producer/Consumer, BlockingCollection, and waiting for changes
body: <p>I'm trying to wrap my head around BlockingCollection and my producer/consumer problem.</p>
  
  <p>What I want to achieve, is the following:</p>
  
  <ul>
  <li>A thread-safe queue of sorts to hold a list of objects ("jobs") in FIFO manner.</li>
  <li>A second thread-safe queue, which holds a list of results of those jobs, also in FIFO manner.</li>
  </ul>
  
  <p>In other words:</p>
  
  <pre><code>Inbound "Job" Data, can come at any time from multiple threads 
     ==&gt; Thread-Safe FIFO Queue 1 "FQ1"
        ==&gt; Async Processing of data in FQ1 (and remove item from FQ1)
           ==&gt; Callback/Results into Thread-Safe FIFO Queue 2 "FQ2"
              ==&gt; Async Processing of data in FQ2 (and remove item from FQ2)
                 ==&gt; Done
  </code></pre>
  
  <p>My humble tries so far are:</p>
  
  <pre><code>private BlockingCollection&lt;InboundObject&gt; fq1;
  private BlockingCollection&lt;ResultObject&gt; fq2;
  
  (...)
  
  Task.Factory.StartNew(() =&gt;
  {
      foreach (InboundObject a in fq1.GetConsumingEnumerable())
         a.DoWork(result =&gt; fq2.Add(result)); //a.DoWork spits out an Action&lt;ResultObject&gt;
  }
  </code></pre>
  
  <p>One of the reasons I chose BlockingCollection is because I want to keep load to a minimum, meaning only do work (and not deal with wait/sleep) when items are actually inside of the collection. I'm not sure if foreach is the correct approach for that.</p>
  
  <p>Please let me know if this is correct or if there is a better approach. Thanks!</p>
  
  <p><strong>Edit</strong>
  I could tell from unit testing that the work inside the task was actually synchronous. New version is as follows:</p>
  
  <pre><code>Task.Factory.StartNew(() =&gt;
  {
      foreach (InboundObject a in fq1.GetConsumingEnumerable())
         Task.Factory.StartNew(async () =&gt; { fq2.Add(await a.DoWork()); });
  }
  </code></pre>
  
  <p>Input is very much appreciated!</p>