title: When does BackgroundWorker thread get killed?
body: <p>I'm developing C# .NET windows Forms application. In which I've a main window and few other window form classes (which are used as dialogs). I've a computationally intensive task(takes 3-4min). When user selects this task from the menu, a new dialog (window) pops up and takes parameters required from the user and it has a progress bar which shows the progress of the task. I'm using BackgroundWorker in this dialog to perform the computation and report progress. This BackgroundWorker also writes all the intermediate values to a log file named <code>status.log</code>.</p>
  
  <p>Problem is, when the user closes this dialog the log file needs to be closed. I guess BackgroundWorker associated with this object will also get destroyed. So, I've wrote even handler for <code>FormClosed</code> event of this dialog and closing the file in that. But it seems that BackgroundWorker isn't killed by then. I mean, BackgroundWorker is now throwing an Exception that file is closed &amp; cannot write to a stream that is closed.</p>
  
  <p>How to handle this situation? When should I close the filestream? When does BackgroundWorker thread get killed?</p>