title: Having some trouble to delete a file using FileStreams in C#
body: <p>I'm writing a program that uses text files in C#.
  I use a parser class as an interface between the file structure and the program. 
  This class contains a <code>StreamReader</code>, a <code>StreamWriter</code> and a <code>FileStream</code>. I use the <code>FileStream</code> as a common stream for the reader and the writer, else these two will conflict when both of them have the file open.</p>
  
  <p>The parser class has a class variable called <code>m_path</code>, this is the path to the file. I've checked it extensively, and the path is correct. <code>OpenStreams()</code> and and <code>ResetStreams()</code> work perfectly, however after calling <code>CloseStreams()</code> in the <code>delete()</code> function, the program goes to the catch clause, so <code>File.Delete(m_path)</code> won't get executed. In other situations the <code>CloseStreams()</code> function works perfectly. It goes wrong when I'm trying to close the <code>StreamReader (m_writer)</code>, but it does give an exception (File is Already Closed).</p>
  
  <pre><code>   /**
       * Function to close the streams.
       */
      private void closeStreams() {
          if (m_streamOpen) {
              m_fs.Close();
              m_reader.Close();
              m_writer.Close(); // Goes wrong
  
              m_streamOpen = false;
          }
      }
  
     /**
       * Deletes the file.
       */
      public int delete() {
          try {
              closeStreams(); // Catch after this
              File.Delete(m_path);
  
              return 0;
          }
          catch { return -1; }
      }
  </code></pre>
  
  <p>I call the function like this:</p>
  
  <pre><code>parser.delete();
  </code></pre>
  
  <p>Could anybody give me some tips?</p>