BackgroundWorker的仍然需要调用调用? [英] BackgroundWorker still needs to call Invoke?

查看:151
本文介绍了BackgroundWorker的仍然需要调用调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最后一个问题 http://stackoverflow.com /问题/ 1952201 /显示,进度条,同时,做 - 一些工作 - 在-C ,人有推荐使用的BackgroundWorker 的。我以为的BackgroundWorker DoWork的方法,你可以直接更新GUI,但是为什么这个函数调用需要使用被称为调用

  toolTip.SetToolTip(按钮,的ToolTipText); 


解决方案

RunWorkerCompleted 回调整理到UI线程; 的DoWork 不是



您应该使用 ReportProgress 。方法以更新的DoWork 在加工过程中UI



请参阅:的How~~V到:在后台运行的操作


In the last question http://stackoverflow.com/questions/1952201/display-progress-bar-while-doing-some-work-in-c, people has recommend use of BackgroundWorker. I thought in BackgroundWorker DoWork method you can update the GUI directly, but why this function call need to be called using Invoke.

toolTip.SetToolTip(button, toolTipText);

解决方案

The RunWorkerCompleted callback is marshalled onto the UI thread; DoWork is not.

You should use the ReportProgress method to update the UI during DoWork processing.

See: How to: Run an Operation in the Background

这篇关于BackgroundWorker的仍然需要调用调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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