title: Waiting BackgoundWorker.DoWork() to finish
body: <p>In our .NET Framework based application we save a huge file using a <a href="https://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker(v=vs.110).aspx" rel="nofollow noreferrer">BackgroundWorker</a> to keep UI responsive. When we close it, we don't want to stop the work in background (default behavior) and truncate the file. </p>
  
  <p>Does a more elegant way to wait for its completion exist compared to this one?</p>
  
  <pre><code>while (this.backgroundWorker1.IsBusy)
  {
      // Keep UI messages moving, so the form remains 
      // responsive during the asynchronous operation.
      Application.DoEvents();
  }
  </code></pre>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong> Basically, what we are trying to achieve, is to see the application to disappear and continue to see a process alive (in the <a href="https://en.wikipedia.org/wiki/Task_Manager_(Windows)" rel="nofollow noreferrer">Task Manager</a>) until the background work is finished.</p>