title: Parallel.ForEach throws exception when extracting a zip file
body: <p>I am reading the contents of a zip file and trying to extract them.</p>
  <pre><code>  var allZipEntries = ZipFile.Open(zipFileFullPath, ZipArchiveMode.Read).Entries;
  </code></pre>
  <p>Now if I extract the using Foreach loop this works fine. The drawback is it is equivalent of zip.extract method and I am not getting any advantage when intend to extract all the files.</p>
  <pre><code>   foreach (var currentEntry in allZipEntries)
          {
              if (currentEntry.FullName.Equals(currentEntry.Name))
              {
                  currentEntry.ExtractToFile($&quot;{tempPath}\\{currentEntry.Name}&quot;);
              }
              else
              {
                  var subDirectoryPath = Path.Combine(tempPath, Path.GetDirectoryName(currentEntry.FullName));
                  Directory.CreateDirectory(subDirectoryPath);
                  currentEntry.ExtractToFile($&quot;{subDirectoryPath}\\{currentEntry.Name}&quot;);
              }
  
          }
  </code></pre>
  <p>Now to take advantage of TPL tried using Parallel.forEach,but that's throwing following exception:</p>
  <blockquote>
  <p>An exception of type 'System.IO.InvalidDataException' occurred in System.IO.Compression.dll but was not handled in user code</p>
  <p>Additional information: A local file header is corrupt.</p>
  </blockquote>
  <pre><code>  Parallel.ForEach(allZipEntries, currentEntry =&gt;
          {
              if (currentEntry.FullName.Equals(currentEntry.Name))
              {
                  currentEntry.ExtractToFile($&quot;{tempPath}\\{currentEntry.Name}&quot;);
              }
              else
              {
                  var subDirectoryPath = Path.Combine(tempPath, Path.GetDirectoryName(currentEntry.FullName));
                  Directory.CreateDirectory(subDirectoryPath);
                  currentEntry.ExtractToFile($&quot;{subDirectoryPath}\\{currentEntry.Name}&quot;);
              }
  
          });
  </code></pre>
  <p>And to avoid this I could use a lock , but that defeats the whole purpose.</p>
  <pre><code>        Parallel.ForEach(allZipEntries, currentEntry =&gt;
          {
              lock (thisLock)
              {
                  if (currentEntry.FullName.Equals(currentEntry.Name))
                  {
                      currentEntry.ExtractToFile($&quot;{tempPath}\\{currentEntry.Name}&quot;);
                  }
                  else
                  {
                      var subDirectoryPath = Path.Combine(tempPath, Path.GetDirectoryName(currentEntry.FullName));
                      Directory.CreateDirectory(subDirectoryPath);
                      currentEntry.ExtractToFile($&quot;{subDirectoryPath}\\{currentEntry.Name}&quot;);
                  }
              }
  
          });
  </code></pre>
  <p>Any other or better way around to extract the files?</p>