将控件添加到后台工作程序中的GUI [英] Add controls to GUI in background worker

查看:78
本文介绍了将控件添加到后台工作程序中的GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有顶部和底部面板的表格.
用户将在顶部面板中进行选择,每次他们在一个键字段上更改值时,我都会破坏底部面板中的控件,然后对另一个应用程序进行耗时的调用(通过COM)并添加列表添加了新控件.此刷新过程需要几秒钟.

I have a form with a top and bottom panel.
The user will be making selections in the top panel, and each time they change a value on one key field I destroy the controls in the bottom panel, then make a time-consuming call to another application (via COM) and add a list of new controls being added. This refresh process takes several seconds.

我希望能够在刷新时禁用底部面板,并允许用户继续在顶部面板中工作.当然,这就是在一个线程上运行的所有GUI.

I'd like to be able to disable the bottom panel while it's being refreshed, and allow the user to be able to keep working in the top panel. Of course, this is all one GUI running on one thread.

说明:

我玩过BackgroundWorker,但是当然它不能直接在主线程的GUI上创建控件.

I played with BackgroundWorker, but of course it cannot directly create controls on the main thread's GUI.

我是否可以做到这一点,即允许用户界面的一部分被禁用并在后台重建,而用户继续在另一部分上工作呢?

Is it possible for me to do this, i.e. allow one part of the GUI to be disabled and rebuilt in the background, while the user continues to work in on another part?

推荐答案

我是否可以做到这一点,即允许用户界面的一部分被禁用并在后台重建,而用户继续在另一部分上工作呢?

Is it possible for me to do this, i.e. allow one part of the GUI to be disabled and rebuilt in the background, while the user continues to work in on another part?

通常,不会. GUI元素/控件必须全部在UI线程上创建和使用,并且无其他地方.

In general, no. GUI elements/controls must all be created and used on the UI thread, and nowhere else.

创建这种情况的最佳方法通常是使用BackgroundWorker或其他技术在后台线程上获取所需的数据,然后在数据加载后构建用户界面完全.

The best way to create this type of scenario is typically to use a BackgroundWorker or other technique to get the required data on a background thread, then build your UI after the data has been loaded completely.

这篇关于将控件添加到后台工作程序中的GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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