My WinForm calls a class which performs some copying actions. I’d like to show the progress of this on a form.
I’d like to use the Backgroundworker, but I don’t know how to report progress from the class to the form (/backgroundworker)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
use the OnProgressChanged() method of the BackgroundWorker to report progress and subscribe to the ProgessChangedEvent of the BackgroundWorker to update the progress in your GUI.
Your copy class knows the
BackgroundWorkerand subscribes toProgressChanged. It also exposes an ownProgressChangedevent that’s raised by the event handler for the background worker’sProgressChangedevent. Finally yourFormsubscribes to theProgressChangedevent of the copy class and displays the progress.Code:
In your form just subscribe to the
ProgressChangedevent ofCopySomethingAsyncand display the progress.