LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Process System Events & Timer

Solved!
Go to solution

I usually use a 'smart delay' that processes events, but I was looking to use a seperate thread to process system events. From menchar's wording here, I get the impression that by using a timer, it is automatically in a different thread. Is that so?

0 Kudos
Message 1 of 3
(4,147 Views)

Standard UI timers run in the same thread as the rest of the user interface. What menchar was referring to is the asyncronous timer, a special control built on top of system multimedia timers which effectively runs in a separate thread. This is a simple demo program that demonstrates async timer features.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(4,142 Views)
Solution
Accepted by topic author TurboMetrologist

An asynchrous timer (in fact, all the async timers for a given process) runs on a common, separate thread.  A "regular" timer is a panel control that will execute a callback on the thread that loaded the panel.

 

System events includes GUI events as I understand it, and these can only be processed on the thread that loaded the panel.  So on the face of it, you would want to process system events using a "regular" timer, not an async timer.

 

I do not know exactly what would happen if you did a process system events on an async timer callback on its separate thread - some things might work, others might not.

 

In the old days, CVI had a "processGUIevents" function, that was different than the "process system events" function.  I don't know if CVI maintains that disctinction any longer.

 

I don't use a timer to do a smart delay, I put the thread to sleep and the OS does the timing, rescheduling the thread after some amount of time.  You don't have a problem then, unless you happen to put the "smart" delay in a separate thread (either one you have explicitly created, or the CVI runtime provided async timer thread) and expect it to update the GUI you've loaded on some other thread.  I intended the "smart" delay to be used only from the main thread - that's the point of it, it allows the process to sleep but will react to user input on the GUI on short notice.

 

It does seem that the NI delay will spinlock, at least in some situations, and NI has told me they process system events during the delay, at least in some situations.  So using the NI Delay() would have the same issues if you use it from some thread other than the thread that loaded any GUI that you are using.

 

If your app doesn't have a GUI, there's no problem using the smart delay on any thread I shouldn't think.

 

Hope this helps.

Message 3 of 3
(4,138 Views)