title: Calling API in Parallel.ForEach sometimes returns incomplete responses
body: <p><em>I apologize to be not able to frame the question properly:</em></p>
  <p><strong>Question:</strong> Is there a possibility that the usage of <code>Parallel.ForEach</code> (used <code>ConcurrentBag</code> to add response from <code>ForEach</code>) is causing incomplete response to be sent to the calling method.</p>
  <p>In below code: <code>processedRecs</code> is getting only <strong>1</strong> <code>Tuple&lt;List&lt;Sample1&gt;, SampleClass2, ResponseClass&gt;</code> in the <code>List</code> but it should get <strong>more than 1</strong>. This happens very rarely, but I am not able to figure out what's causing this.</p>
  <p>I have looked into all the logs/DB calls, there were no failures in the method <code>SampleReq</code>.</p>
  <pre><code>public ResponseClass2 ManageOrders(SampleRequest request)
  {
      //.
      //.
      //.
      var processedRecs = FetchOrderInfo(request);
  
      // here &quot;processedRecs&quot; are getting only 1
      // Tuple&lt;List&lt;Sample1&gt;, SampleClass2, ResponseClass&gt; in the List
      foreach (var tp in processedRecs)
      {
          //.
          //.
          //.
          // but &quot;SampleReq&quot; method had processed 3, so the List&lt;Touple....&gt;
          // should have count 3 instead of 1.
      }
  }
  
  private List&lt;Tuple&lt;List&lt;Sample1&gt;, SampleClass2, ResponseClass&gt;&gt; FetchOrderInfo(
      SampleRequest request)
  {
      //.
      //.
      //Processing the request... no issues here
      //.
  
      ConcurrentBag&lt;Tuple&lt;List&lt;Sample1&gt;, SampleClass2, ResponseClass&gt;&gt; tp =
          new ConcurrentBag&lt;Tuple&lt;List&lt;Sample1&gt;, SampleClass2, ResponseClass&gt;&gt;();
  
      Parallel.ForEach(arranged,
      samObj =&gt;
      {
          var sampleResponse = TEngine.SampleReq(request.Email, samObj.Item2,
              request.pIndex)
                  .GetAwaiter()
                  .GetResult();
          tp.Add(Tuple.Create(samObj.Item1, samObj.Item2, sampleResponse));
      });
  
      return new List&lt;Tuple&lt;List&lt;Sample1&gt;, SampleClass2, ResponseClass&gt;&gt;(tp);
  }
  
  // Method &quot;SampleReq&quot; calls another API to get the results... we are calling this
  // multiple times for different set of data and then merging this info.
  public static async Task&lt;ResponseClass&gt; SampleReq(string email,
      SampleClass2 selectedObj, int pIndex)
  {
      // These responses are getting logged and we didn't get any issues here.
  }
  </code></pre>