title: Unreliable parallel loop fails 4 out of 400 times
body: <p>I have a Parallel foreach function that creates a new instance of a class, that manipulates a picture, and saves it to the disk...</p>
  
  <p>However approximately 4 times out of 400, the picture gets saved to the disk, but without being manipulated, my theory is that when it happens, some of the propperties existing in my class is null, when they are not suppost to...</p>
  
  <p>The 4 (sometimes 3) errors mostly occurs in the first 10 images of the parallel loop.</p>
  
  <p>There is no error message, it justs skip some of my code, for some reason... My breakpoint doesn't work when it is parralel, so it is hard to debug.</p>
  
  <p>Any advice on how to proceed / debug / fix ?</p>
  
  <p><strong>The code as requested</strong></p>
  
  <pre><code>    private static void GenerateIcons(Effects effect)
      {
          DirectoryInfo dir = new DirectoryInfo(HttpContext.Current.Server.MapPath(@"~\Icons\Original\"));
  
          FileInfo[] ff = dir.GetFiles();
  
          string mappath = HttpContext.Current.Server.MapPath(@"~\Icons\");
  
          List&lt;string&gt; paths = new List&lt;string&gt;();
  
          string ids = GetAllEffectIds(effect.TinyUrlCode);
  
          Parallel.ForEach(ff, item =&gt;
          {
              if (!File.Exists(mappath + @"Generated\" + ids + "-" + item.Name))
              {
                  paths.Add(mappath + @"Generated\" + ids + "-" + item.Name);
                  ApplyEffects f = new ApplyEffects(effect, item.Name, mappath);
                  f.SaveIcon();
  
  
              }
          });
          //Zip icons!
          ZipFiles(paths, effect.TinyUrlCode, ids, effect.General.Prefix);
  
      }
  </code></pre>