LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem updating ListBox using Threads

Hello all and thanks for your answers.

I'll try to explain how my app is working .

It is really a win32 app, and its main thread consists of a 'while' which responds to windows messages.

Before entering this while, I launch my CVI_Thread (which just initializes everything in CVI and calls to RunUserInterface()) so this thread is responsible for respondig to user interaction -pushing controls- in CVI. I also launch my LAN_Thread, which waits for LAN Messages (through sockets).

So when I say that the Listbox updates correctly with user interaction, I mean that when I click a control (for example 'add item to the list'), I launch a normal CVI CALLBACK and this callback (which is attended automatically by my CVI_Thread and its RunUserInterfce() loop) calls for the control to update and the changes appear on the control right away. So I don't make any call to ProcessDrawEvents(), this is what I meant when I said that I called for the control to update.

The problem is that when I receive a message through LAN_Thread with new items, I also call for an update of the ListBox Control, the changes on the control doesn't appear.

Now on with the solutions. As I mentioned in past posts, the only solution that has proven right for me is to turn the attribute VISIBLE 'off' and then 'on' again on the ListBox Control after making the changes on it. The last values now appear but the effect is that the Control 'blinks', which causes a very bad effect on my app.

I have tried to make a 'PostDeferredCallToThread' to a function in the CVI_Thread upon receiving the LAN Message. This function updates the listbox with the items received in the LAN Message. But this didn't work, as the ListBox Control wouldn't update to show the new values.

Right now I'm out of ideas, and I'm going with the blinking solution.

 

Daniel

0 Kudos
Message 11 of 13
(1,388 Views)
Comadreja,

Is there any way possible that you can post an example of what you're talking about (not with TCP, but just 2 threads and how you are doing this). You said that PostDeferredCallToThread does not work, but what exactly does it do? It seems easier to just update the information in the CVI thread and just pass information from the TCP thread to it through Thread-Safe Queues or something else along those lines.

Brandon Vasquez | Software Engineer | Integration Services | National Instruments
0 Kudos
Message 12 of 13
(1,365 Views)
Daniel,

Reading through your detailed description of your app, I don't see any reason why the listbox shouldn't update immediately. The RunUserInterface call in your CVI thread should take care of redrawing the listbox as soon as the OS performs the thread switch.

Based on your description, I wrote a small sample program that does something similar to what you describe. The only major difference is that instead of waiting for network data in the LAN thread, it updates the listbox at a specific time intervals. When I run this project the listbox updates right away, as expected. One thing you can do is to try to run it yourself, and if it also works for you, you can then focus on gradually removing the differences between them until the behavior is the same.

Luis



0 Kudos
Message 13 of 13
(1,354 Views)