简体   繁体   中英

Figure out why controls aren't updated in the user interface in a Mobile Forms application

Background

This is a Compact Framework 3.5 Forms application. In the process of showing a form, static (this means controls placed in the form as is ) controls are populated in the user interface thread, while ones which may need loading data, are populated in a separate thread from the user interface one.

I'm using Control.Invoke in order to synchronize populating controls with data in the user interface thread.

Note user interface doesn't get stuck, and it's running as expected.

Problem

Controls like ListBox , even if they've items, these aren't shown in the user interface.

Whenever an item is added, code calls ListBox.Update method in order to redraw it.


Will you give me some hint about what's happening?

NOTE : I could paste here some code, but I find that useless, because it's just about starting a thread by creating a one ( new Thread(...).Start() ) and, during this thread's execution, I call some form Invoke method.

Thank you in advance for your suggestions and time.


UPDATE I got it working if I create a control like ListBox in the synced with UI thread action using Control.Invoke . Anyway, I've still need to solve that when control is created using the designer, because it's easier to place controls in that way. Thanks.

I've noticed lots of controls that get created in a separate thread behave peculiarly or vanish altogether when they are returned to the main thread of execution. Perhaps they become orphan or...something.

Here's what has worked best for me: Place the controls on the form (set Visible=false, Width=0, etc., if you don't want to see them) and just pass the data back from your thread. When the data comes back, populate your controls with the data. Typically, I will create a class that contains the returned values that I am looking for, and return an instance of the class.

That said, I must tip my hat and say Chris Tacke does know what he's doing. I've taken guidance from him since XP came out and I was using Outlook Express to read from Microsoft's Newsgroups.

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