The MSDN Docs says
If the operation raises an exception that your code does not handle, the BackgroundWorker catches the exception and passes it into the RunWorkerCompleted event handler, where it is exposed as the Error property of System.ComponentModel.RunWorkerCompletedEventArgs
But when I tried
_workers[i].DoWork += (s, args) =>
{
throw new Exception("Error!");
};
I get Exception Unhandled error ... The code doesn't seem to go to RunWorkerCompleted
. How are errors supposed to be handled?
I have setup simple handlers
_workers[i].DoWork += (s, args) =>
{
throw new Exception("Error!");
}
...
_workers[i].RunWorkerCompleted += (s, args) =>
{
if (args.Error != null) {
string dummy = args.Error.Message;
}
...
};
The code never leaves DoWork
If an exception is thrown and passes through user frames but is then not caught by user code, it is considered "user-unhandled".
So I think there are 3 possibilities:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With