LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

locking the GUI

Is there a way to ignore GUI events .. .effectively locking it out?   My problem is that I have a list box with items in it. When the user clicks an item I perform an action that takes about 1 second to complete.  If the user clicks too much on the list box during this action the program will generate a GP failure.
 
I tried to block the events with an  ."  if (ProcessActive ==  0 ) { ... switch(event) {   " construct, but it doesn't help.  I once saw a function to lock out the GUI entirely, but don't remember the function call.
 
Thanks,
Phil
0 Kudos
Message 1 of 3
(3,137 Views)
Hi Phil,

A general rule of thumb is not to do anything time consuming in a UI callback. If the UI event needs to trigger a time consuming task, it is a good idea to have the UI callback launch a separate thread (e.g. CmtScheduleThreadPoolFunction) to do the task. If you don't move the task to a separate thread, your UI callback doesn't return until the task finishes. Doing the work in a separate thread allows your main thread to continue processing events, which means your UI is responsive, and your "ProcessActive ==  0" solution should work.

Mert A.
National Instruments
0 Kudos
Message 2 of 3
(3,135 Views)

Provided that Mert's suggestion is crucial, simply changing the control to indicator may help you to avoid control callback to be called when executing your long-lasting task without need to handle a global variable; control callback could then look like this one:

if (event != EVENT_COMMIT) return 0;
SetCtrlAttribute (panel, control, ATTR_CTRL_MODE, VAL_INDICATOR);
CmtScheduleThreadPoolFunction (...);
return 0;

After completion of the scheduled function you could PostDefferredCall a function to the main thread to restore normal control state.



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?
0 Kudos
Message 3 of 3
(3,127 Views)