Specifications
4 Programming GUIs
4-20
Interrupting Executing Callbacks
By default, MATLAB allows an executing callback to be interrupted by
subsequently invoked callbacks. For example, suppose you have created a
dialog box that displays a progress indicator while loading data. This dialog
could have a “Cancel” button that stops the loading operation. The “Cancel”
button’s callback routine would interrupt the currently executing callback
routine.
There are cases where you may not want user actions to interrupt an executing
callback. For example, a data analysis tool may need to perform lengthy
calculations before updating a graph. An impatient user may inadvertently
click the mouse on other components and thereby interrupt the calculations
while in progress. This could change MATLAB’s state before returning to the
original callback.
The following sections provide more information on this topic:
•“Controlling Interruptibility”
•“The Event Queue”
•“Event Processing During Callback Execution”
Controlling Interruptibility
All graphics objects have an Interruptible property that determines whether
their callbacks can be interrupted. The default value is
on, which means that
callbacks can be interrupted. However, MATLAB checks the event queue only
when it encounters certain commands –
drawnow, figure, getframe, pause,
and,
waitfor. Otherwise, the callback continues to completion.
The Event Queue
MATLAB commands that perform calculations or assign values to properties
execute as they are encountered in the callback. However, commands or actions
that affect the state of the figure window generate events that are placed in a
queue. Events are caused by any command that causes the figure to be redrawn
or any user action, such as a button click or cursor movement, for which there
is a callback routine defined.
MATLAB processes the event queue only when the callback finishes execution
or when the callback contains the following commands: