LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Panels and multithreading

Again, a multithreading question:
 
In a second thread I am acquiring data. I want this data to appear on my application's main panel, which was created in the first thread. If I understand it right, it is not possible to use SetCtrlVal in the second thread, on a control from the main thread. A solution would be running a timer in a first thread to display the data. But since this timer callback function will only be executed when no other functions from the first thread are executing, so I would have to insert a ProcessSystemEvents () everywhere throughout my code.
 
Is there a better solution to do this, or am I really stuck here?
0 Kudos
Message 1 of 4
(3,566 Views)
What is your main thread doing that's so important?  Are you compute bound somehow on the main thread?  Does it spend any time waiting?  Did you call RunUserInterface() from the main thread?  Are callbacks being executed?  CVI does a ProcessSystemEvents() on return from a callback.

If you can somehow structure the main thread as an iteration (a loop), you could have the second thread acquire the data and post it to a common area, then read it from the main thread to update the control once per iteration.  This is a "reader writer" problem, if the data isn't "atomic" (like an int or a double) you'd have to synchronize the read / write to preclude reading a partially written result.

If you are using the NI Delay() function, it has a built in ProcessSystemEvents() call that will allow a timer control to fire.  SyncWait() will do this too I believe.

Hayes


Message 2 of 4
(3,556 Views)
Wim,

Actually, you should be able to call SetCtrlVal across threads. You can see this in the "Different Approaches to Multithreaded User Interface Programming" topic of the online help (it's referred to as the "second approach"). You can also see an example of this in samples\utility\Threading\ThreadPool\OnePanel\OnePanel.cws.

Luis
NI
Message 3 of 4
(3,545 Views)
Thanks a lot Luis, that was the answer I needed to hear smileyhappy:
0 Kudos
Message 4 of 4
(3,530 Views)