title: Always getting count zero using Parallel execution instead of forEach loop in c sharp
body: <p>I have a scenerio in which i have to call a third party server. Here on my side i have a array in which some record are exist, and every record in array need to send over third party call and get some byte of data and this returned data added in dictionary. initially i traverse array using forEach but it take more than 50 seconds, than i come over to use parallel.forEach to reduce time window, but at last dictionary count zero.
  please help   </p>
  
  <pre><code> public void GenerateMultipleReport(ReportRenderDTO[] reportdetailCollection)
      {
          try
          {
             pdfMergedData = new List&lt;Dictionary&lt;string, byte[]&gt;&gt;();
  
                  Parallel.ForEach(reportdetailCollection.Cast&lt;ReportRenderDTO&gt;(), async (reportdetails) =&gt;
                  {
                      await Task.Run(() =&gt; GetBytesFromServer(reportdetails));
  
                  });  
  
  
              MergePDF(pdfMergedData);
  
          }
  </code></pre>
  
  <p>And Method GetBytesFromServer have below body : </p>
  
  <pre><code> private void GetBytesFromServer(ReportRenderDTO reportdetails)
      {
          Dictionary&lt;string, byte[]&gt; pdfDataDicitionary = new Dictionary&lt;string, byte[]&gt;();
          _logger.Debug("Method:GenerateMultipleReport()(BL), Role:generates a report from template ,Parameters:reportdetails, Return:void");
          string authorityName;
          var jss = new JavaScriptSerializer();
          var _jsonObject = (object[])jss.Deserialize(reportdetails.EOSParameters, typeof(object));
          Dictionary&lt;string, object&gt; _values = (Dictionary&lt;string, object&gt;)_jsonObject[0];
          Dictionary&lt;string, string&gt; _params = new Dictionary&lt;string, string&gt;();
  
          _values.Keys.ToList().ForEach(x =&gt; _params.Add(x, _values[x].ToString()));
  
          if (!string.IsNullOrWhiteSpace(reportdetails.AuthorityKode))
          {
              authorityName = _iEarchiveDocumentRepository.GetAuthorityName(reportdetails.AuthorityKode);
          }
          else
          {
              var userData = UserProfileInfo.GetUserProfile();
              authorityName = userData != null ? userData.myndighedData.Tekst : string.Empty;
          }
  
  
          Guid _documentId;
          _documentId = EOSPDFGenerator.Instance.Render(reportdetails.WorkFlowName, reportdetails.DocumentType, authorityName, _params);
          byte[] pdfData = this.RenderMultipleReport(_documentId.ToString(), reportdetails.DocumentType);
          pdfDataDicitionary.Add(reportdetails.WorkFlowName, pdfData);
          pdfMergedData.Add(pdfDataDicitionary);
  
  
      }
  </code></pre>
  
  <p>But always count of pdfMergedData is zero ....
  Please tell me what is the problem.....</p>