Quantcast
Channel: Avventure sul Web » tips
Viewing all articles
Browse latest Browse all 8

Handling exceptions within BackgroundWorker object

$
0
0

Here’s a little sample that proves BackgroundWorker eats exceptions in DoWork, and makes them available to you in RunWorkerCompleted:


var worker = new BackgroundWorker();
worker.DoWork += (sender, e) =>
{
  throw new InvalidOperationException("oh shiznit!");
};
worker.RunWorkerCompleted += (sender, e) =>
{
  if(e.Error != null)
  {
    MessageBox.Show("There was an error! " + e.Error.ToString());
  }
};
worker.RunWorkerAsync();

Archiviato in:Programmazione Tagged: .net, development, tips

Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles