title: How can I tell if a streamwriter is closed?
body: <p>I'm using a streamwriter in combination with a background worker, for logging.</p>
  
  <p>As such, I have </p>
  
  <pre><code>System::Void
  MyUI::execBWorker_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
  
  String^ outputPath = _clr::Settings::ApplicationLogPath("_log.txt", true, false);
  logfile_ = gcnew StreamWriter(outputPath,true);
  
  DoStuff();
  logfile_-&gt;Close();
  }
  </code></pre>
  
  <p>Things in the DoStuff() method raise the Progress event.</p>
  
  <pre><code>System::Void
  MyUI::execBWorker_ProgressChanged(System::Object^  sender, System::ComponentModel::ProgressChangedEventArgs^  e) {
  logfile_-&gt;WriteLine("something");
  }
  </code></pre>
  
  <p>I think this really smells.  How can I make it better, or at least how can I check the logfile hasn't been closed?  There are a lot of messages, so I'm concerned about opening and closing the logfile continuously.</p>