title: Parallel.ForEach issues - Read Write On A File - File Is In Use Error
body: <p>I am really really confused about Parallel.ForEach...  How does it work?<br>
  The code below has an error -> <code>File Is In Use</code></p>
  
  <pre><code>Parallel.ForEach(list_lines_acc, (line_acc, list_lines_acc_state) =&gt;
  {
       FileStream file = 
           new FileStream(GPLfilePath, FileMode.Open, FileAccess.ReadWrite);
       StreamReader reader = new StreamReader(file);
       var processed = string.Empty;
       Ok_ip_port = string.Empty;
       while (reader.EndOfStream)
       {
           if (string.IsNullOrEmpty(Ok_ip_port))
           {
               Ok_ip_port = reader.ReadLine();
           }
           else
           {
               string currentLine = reader.ReadLine();
               processed += currentLine + Environment.NewLine;
           }
       }
       StreamWriter writer = new StreamWriter(file);
       writer.Write(processed);
  
       reader.Close();
       writer.Close();
       file.Close();
  });  
  </code></pre>
  
  <p>Would you please show me how can I fix that? This code is just an example.  </p>
  
  <p>I want to work with string arrays &amp; Lists inside Parallel.ForEach, but there is always a problem for adding or editing those collections. Can you please provide an example? I am using Visual Studio 2010 + .NET Framework 4.0</p>