QUESTION: Re use of .NET Backgroundworker, is there not a way to let exceptions pass back normally to main thread?
BACKGROUND:
The BackgroundWorker
automatically passes back the exception. It's in the AsyncCompletedEventArgs.Error property when you hook the RunWorkerCompleted
event.
If you like, you can wrap and rethrow the exception in this event handler - keeping in mind that there's a bug in the framework that will cause the "outer" exception to be thrown instead because you're in the middle of an Invoke
.
An exception that occurs on a background thread in a .NET application is a catastrophic error that can and will bring down the entire process; the only way to deal with this is to wrap all of the activity in a try-catch block and save any exception that occurred, which is exactly what the BackgroundWorker
does.
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