后台工作如何 [英] Background Worker How To

查看:94
本文介绍了后台工作如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现后台工作到我的程序,这样,当我运行程序它不会冻结,并开始获取我需要的数据。

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.

推荐答案

背景工人,在后台运行,做的工作不会中断/阻止你的主线程的线程。

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

您可以阅读更多这里

在快捷方式:

在DoWork的做你的阻塞操作。每当你可以,报告您有多远通过使用(发件人为BackgroundWorker的).ReportProgress(50)的操作; 例如报告50%的完成

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.

您可以有你的主线程订阅ProgressChanged事件,该事件可以更新GUI或做当进度发生变化应该发生的其他任务。

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.

这篇关于后台工作如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆