Background Worker How To

回眸只為那壹抹淺笑 提交于 2019-12-01 09:04:39

问题


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.


回答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.



来源:https://stackoverflow.com/questions/15149235/background-worker-how-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!