从另一个线程更新进度栏 [英] Updating a Progress Bar from Another Thread

查看:92
本文介绍了从另一个线程更新进度栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主线程和另一个执行某些计算的线程上都有一个Windows窗体.我想通过另一个线程中完成的工作来更新表单上的状态栏.最好的方法是什么?

I have a windows form on the main thread and another thread that does some calculations. I'd like to update the status bar on my form from the work being done in the other thread. What's the best way to do this?

到目前为止,我已经尝试过的所有操作只会使事情运行非常缓慢.我正在使用Visual Studio 2005.

So far everything I've tried just makes things run really slowly. I'm using Visual Studio 2005.

推荐答案

请确保仅从主线程更新用户界面,否则将出现问题.您可以通过调用Invoke来切换线程上下文.在此处上有一篇不错的文章.

Make sure that you only update the user interface from the main thread or else you will have problems. You can switch your thread context by calling Invoke. There's a good post here on that.

这篇关于从另一个线程更新进度栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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