Background Worker How To

I’m trying to implement background worker into my program, so that it wont freeze when i run the program and starts retrieving the data I need.

I’m not quite sure how background worker works.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Background workers are threads that run in the background and do work without interrupting/blocking your main thread.

You can read more here.

In quick terms:

In DoWork do your blocking operation. Whenever you can, report how far through you are with the operation using (sender as BackgroundWorker).ReportProgress(50); for example to report 50% completion.

You can have your main thread subscribe to the “ProgressChanged” event, which can update GUI or do other tasks which should occur when the progress has changed.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x