title: Parallel.ForEach behaving like a regular for each towards the end of the iteration
body: <p>I am having this issue when I ran something like this:</p>
  
  <pre><code>Parallel.ForEach(dataTable.AsEnumerable(), row =&gt;
  {
     //do processing
  }
  </code></pre>
  
  <p>Assuming that there are 500+ records say 870. Once the Parallel.ForEach completes 850, it seems to be running sequentially i.e. only 1 operation at a time. It completed 850 operations very fast but when it comes close to the end of the iteration it becomes very slow and seems to be performing like a regular for each. I even tried for 2000 records. </p>
  
  <p>Is something wrong in my code? Please give suggestions.</p>
  
  <p>Below is the code I am using </p>
  
  <p>Sorry I just posted the wrong example. This is the correct code:</p>
  
  <pre><code>Task newTask = Task.Factory.StartNew(() =&gt;
  {
      Parallel.ForEach(dtResult.AsEnumerable(), dr =&gt;
      {
          string extractQuery = "";
          string downLoadFileFullName = "";
          lock (foreachObject)
          {
  
              string fileName = extractorConfig.EncodeFileName(dr);
              extractQuery = extractorConfig.GetExtractQuery(dr);
              if (string.IsNullOrEmpty(extractQuery)) throw new Exception("Extract Query not found. Please check the configuration");
  
              string newDownLoadPath = CommonUtil.GetFormalizedDataPath(sDownLoadPath, uKey.CobDate);
              //create folder if it doesn't exist
              if (!Directory.Exists(newDownLoadPath)) Directory.CreateDirectory(newDownLoadPath);
              downLoadFileFullName = Path.Combine(newDownLoadPath, fileName);
          }
          Interlocked.Increment(ref index);
  
          ExtractorClass util = new ExtractorClass(SourceDbConnStr);
          util.LoadToFile(extractQuery, downLoadFileFullName);
          Interlocked.Increment(ref uiTimerIndex);
      });
  });
  </code></pre>