03-28-2014 03:03 PM
I need a bit of help with the basics of UI callbacks and threads.
Here is the scenario: There are two controls
1. Numeric control with callback for EVENT_VAL_CHANGED
2. Button with callback for EVENT_COMMIT
RunUserInterface() is called once early in the program. User enters a value in the numeric control with the keyboard (just numbers), then they click on the button.
This fires the following events:
EVENT_VAL_CHANGED (numeric) --> numeric callback runs
EVENT_COMMIT (numeric)
EVENT_LEFT_CLICK (button)
EVENT_LEFT_CLICK_UP (button)
EVENT_COMMIT (button) --> button callback runs
EVENT_LOST_FOCUS (numeric (?))
EVENT_GOT_FOCUS (button)
Can parts of the button callback execute before the numeric callback completes?
Thanks!
Solved! Go to Solution.
03-28-2014 03:20 PM
03-28-2014 03:44 PM
Thanks, ebalci!
I suppose I should have been more clear -- sorry. I do not want the button callback to execute before the numeric callback.
I have a weird bug report (of unknown reliability) that might be explainable of the button callback ran before the numeric callback. I can't replicate it in debug or release.
To be safe, I already did what you suggested, but in reverse. I put another direct call to the numeric callback at the start of the button callback. My hope was that if there were thread-related issues, that numeric callback would execute first inside the thread that eventually processes the button callback.
However I was unsure if my approach was addressing a physically possible scenario, in which the button callback executes some or all of its code before the numeric callback. Do you know if that is possible (in the initial scenario outlined)?
Thanks,
Ian
03-28-2014 09:24 PM
03-31-2014 10:39 AM
Ok, I think I need some official NI clarification: Do two separate UI callbacks triggered by one user action but different events run in the same thread, or not? (Pls see my OP for the an example)
elbaci has indicated that they could be. However, I can see one clue to the answer: the CVI help warns to be careful with using ProcessSystemEvents with a callback: "Take care when using ProcessSystemEvents, because it can allow other callback functions to execute before it completes." which seems to imply that by not calling ProcessSystemEvents (which is my situation) then the second callback will not complete before the first.
(Just to be clear here: I do not use or care about ProcessSystemEvents for my question -- it just was drawn into the discussion.)
Thanks,
Ian
03-31-2014 10:48 AM - edited 03-31-2014 10:52 AM
Hi Ian,
You may not be calling ProcessSystemEvents explicitly. However, some functions may force it. Even a Sleep() may cause other waiting events to get processed.
You might also find reading SetSleepPolicy function help useful.
These are not necessarily documented info. Most are from experience.
I will also enjoy an official clarification.
Ian it may help people if you can provide a code excerpt from your application..
03-31-2014 12:38 PM
To answer Ian's question, yes, all UI events are sent in the thread that owns the panel. Here's the relevant topic from the CVI help.
Luis
03-31-2014 01:38 PM
Thanks once again Luis!
It is a relief the know that I do not have to revisit all my code to search for places where the order of UI callback calls could be random ... so long as the events are raised in a consistent order. 🙂
--Ian