All,I already knew the basic usage the BackgroundWorker
to handle multiple thread case in the WinForm . And the code structure looks like below.
In the
The Result
property in RunWorkerCompletedEventArgs
is the value you have assigned to the Result property of DoWorkEventHandler
in DoWork()
.
You can assign anything you like to this, so you could return an integer, a string, an object/composite type, etc.
If an exception is thrown in DoWork()
then you can access the exception in the Error
property of RunWorkerCompletedEventArgs
. In this situation, accessing the Result property will cause an TargetInvocationException
to be thrown.