title: How would i restart StreamWriter onced it has been used?
body: <p>I am using a Streamwriter method for a button click to run a test, but after the test is complete I want to run it again and record the results in the same text file.</p>
  
  <p>I always receive an error that the file is still in another process even though the previous test has been completed. I have tried using .Close() but then I get a "Can't write to closed textwriter" error message.</p>
  
  <pre><code> StreamWriter ResultsFile = new StreamWriter(FileName, true);
  
      public void ToFile()
      {
          ResultsFile.AutoFlush = true;
          Console.SetOut(ResultsFile);
          Console.WriteLine("Regression Test Performed at {0}", thisDate);
          Console.WriteLine("-----");
  
      }
  
     [Test]
      public void NewTextFile()
      {
          ToFile();
          const int requiredNumber = 5;
          for (var i = 0; i &lt; requiredNumber; i++)
          {
              Console.WriteLine("New ID assigned to ABC");
              Console.WriteLine("-----");
           }
       }
  </code></pre>