backgroundworker
时间: 2023-08-19 07:14:32 浏览: 214
BackgroundWorker是一个用于执行异步操作的类。当调用BackgroundWorker.RunWorkerAsync()方法时,会触发DoWork事件,该事件用于执行耗时的操作。需要注意的是,DoWork事件内部的代码运行在非UI线程上,所以应避免在该事件内部与用户界面进行交互。与用户界面交互的操作应放置在ProgressChanged和RunWorkerCompleted事件中。\[1\]\[2\]
另外,BackgroundWorker还提供了ReportProgress方法,用于在执行异步操作的过程中报告进度。当调用BackgroundWorker.ReportProgress(int percentProgress)方法时,会触发ProgressChanged事件。该事件的ProgressChangedEventArgs.ProgressPercentage属性可以接收来自ReportProgress方法传递的percentProgress参数值,而ProgressChangedEventArgs.UserState属性可以接收来自ReportProgress方法传递的userState参数。\[3\]
总之,BackgroundWorker是一个方便的工具,可以帮助我们在后台执行耗时的操作,同时保持用户界面的响应性。
#### 引用[.reference_title]
- *1* *3* [BackgroundWorker使用总结](https://blog.csdn.net/CodeRookieGuo/article/details/72723310)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [C#多线程之BackgroundWorker](https://blog.csdn.net/sinat_31608641/article/details/106116204)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文