RunWorkerCompletedEventArgs and Errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pagates

    RunWorkerCompletedEventArgs and Errors

    Hi All,

    I'm playing with the BackgroundWorke r control, and am having a little
    trouble figuring out Exception Handling. MSDN makes it sound so simple - if
    an exception is thrown in DoWork, then e.Error should not be null.

    However, I can't get DoWork to process an exception "properly". I always
    get an Unhandled Exception error.

    For instance, here's the simplest case:

    private void BGWorker_DoWork (object sender, DoWorkEventArgs e)
    {
    // I can never get past here
    throw new ApplicationExce ption("This is an exception");
    }

    private void BGWorker_RunWor kerCompleted(ob ject sender,
    RunWorkerComple tedEventArgs e)
    {
    if (e.Error != null)
    MessageBox.Show ("There was an error: " + e.Error.Message );
    }

    My searches online seem to indicate that other people have had similar
    problems, but I haven't found a workaround, solution, or whether this is
    considered a bug.

    Any help is much appreciated.

    Thanks,
    PAGates
Working...