Changing the property of a control from a BackgroundWorker C#

一个人想着一个人 提交于 2019-12-03 17:06:34
itowlson

As C. Ross says, you can do this directly using the Control.Invoke family of methods, but it may be easier -- and is probably more idiomatic -- to do it indirectly by handling the BackgroundWorker.ProgressChanged event. While DoWork is raised on the background thread, ProgressChanged is raised on the UI thread. So updating your text in ProgressChanged doesn't require Invoke.

In addition, this keeps your worker function free of UI dependencies which will make it easier to test.

You need to use InvokeRequired and BeginInvoke.
This page tells you about how to do it. Here's the MSDN page.

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