title: Exception of type 'System.IO.IOException' occurred in mscorlib.dll - The process cannot access the file because it is being used by another process
body: <p>Probably there are number of questions like this one on SO but none of them has been able to fix my issue. I am  creating  a text file programatically and witting the text in to it using this code:</p>
  
  <pre><code> for (int y = 0; y &lt; image.Height; y++)
              {
                  for (int x = 0; x &lt; image.Width; x++)
                  {
                      string path = @"E:\Example.txt";
  
  
                      Color pixel = image.GetPixel(x, y);
                      if (!File.Exists(path))
                      {
                        //  File.Create(path);
                         File.Create(path).Dispose();
                          using (TextWriter tw = new StreamWriter(path))
                          {
                              tw.WriteLine("Value at" + x + "" + y + "" + "is:" +pixel);
                              tw.Close();
                          }
  
                      }
  
                      else if (File.Exists(path))
                      {
                          File.AppendAllText(path,
                     "Value at"+"" + x + "" + y + "" + "is:" +""+ pixel + Environment.NewLine);
                          //using (TextWriter tw = new StreamWriter(path))
                          //{
                          //    tw.WriteLine("The next line!");
                          //    tw.Close();
                          //}
                      }
                      if (pixel.R == keywordBytes[0] &amp;&amp; pixel.G == keywordBytes[1] &amp;&amp; pixel.B == keywordBytes[2])
                      {
  
                          firstMatchingBytePos = new Point(x, y);
                          KeywordFound(keyword, firstMatchingBytePos);
                      }
                  }
              } 
  </code></pre>
  
  <p>I want to write the value of each pixel in the text file. It works for few values and then suddenly stops throwing an above exception.</p>
  
  <p>Moreover i have checked the security property of the file and made sure that i have the full control over the file. I am not able to figure it out.</p>
  
  <p>Any suggestions to fix this would be really appreciated</p>