简体   繁体   中英

Add controls to GUI in background worker

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.

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.

Illustrated:

在此处输入图片说明

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, ie 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, ie allow one part of the GUI to be disabled and rebuilt in the background, while the user continues to work in on another part?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM