title: How to handle exceptions from a BackgroundWorker thread?
body: <p>In a WPF app I have a sheduled database access task, periodically run by a timer and this task have been executed in a BackgroundWorker thread.</p>
  
  <p>When connection attempt failed I raise an exception by <code>try_catch</code> construction and I want to update a Status Bar text in a UI thread. </p>
  
  <p>Is there some prebuild event construction in a <code>BackgroundWorker</code> for implementing this, something like <code>DoWorkEventHandler</code> or <code>RunWorkerCompletedEventHandler</code>, which can be used for this? If not, how to do it better?</p>
  
  <p><strong>Edited (added):</strong></p>
  
  <p>If I want to handle the exception inside <code>RunWorkerCompletedEventHandler</code>, using <code>e.Error</code> parameter, it doesn't work. In case I leave exception unhandled in the <code>BackgroundWorker</code> thread, application hangs on and debugger points to the string of code which is excuted inside <code>BackgroundWorker</code> thread, saying that: <strong><em>Exception was unhandled by user code</em></strong>. </p>
  
  <p>So, in this case, thread doesn't just stop, signalling to <code>RunWorkerCompletedEventHandler</code> that it stopped with error, but the whole application stop working.</p>