13 Manage Callback Execution
Interrupt Callback Execution
In this section...
“How to Control Interruption” on page 13- 2
“Callback Behavior When Interruption is Allowed” on page 13- 2
“Example” on page 13- 3
MATLAB lets you control whether or not a callback function can be interrupted while
it is executing. For instance, you can allow users to stop an animation loop by creating
a callback that interrupts the animation. At other times, you might want to prevent
potential interruptions, when the order of the running callback is important. For
instance, you might prevent interruptions for a WindowButtonMotionFcn callback that
shows different sections of an image.
How to Control Interruption
Callback functions execute according to their order in a queue. If a callback is executing
and a user action triggers a second callback, the second callback attempts to interrupt
the first callback. The first callback is the running callback. The second callback is the
interrupting callback.
Two property values control the response to an interruption attempt:
- The Interruptible property of the object owning the running callback determines if
interruption is allowed. A value of 'on' allows the interruption. A value of 'off'
does not allow the interruption. The default value is 'on'. - If interruption is not allowed, then the BusyAction property (of the object owning the
interrupting callback) determines if MATLAB enqueues or discards the interrupting
callback. A value of 'queue' allows the interrupting callback to execute after the
running callback finishes execution. A value of 'cancel' discards the interrupting
callback. The default value is 'queue'.
Callback Behavior When Interruption is Allowed
When an object’s Interruptible property is set to 'on', its callback can be interrupted at
the next occurrence of one of these commands: drawnow, figure, getframe, waitfor,
or pause.