MATLAB: How does the canceling callback of waitbar works

gui waitbar callbackMATLAB

I am learning GUI design and puzzled about the mechanism of callback execution of waitbar.
Here is the example in the help of waitbar
function [valueofpi step] = approxpi(steps)
% Converge on pi in steps iterations, displaying waitbar.
% User can click Cancel or close button to exit the loop.
% Ten thousand steps yields error of about 0.001 percent.
h = waitbar(0,'1','Name','Approximating pi...',...
'CreateCancelBtn',...
'setappdata(gcbf,''canceling'',1)');
setappdata(h,'canceling',0)
% Approximate as pi^2/8 = 1 + 1/9 + 1/25 + 1/49 + ...
pisqover8 = 1;
denom = 3;
valueofpi = sqrt(8 * pisqover8);
for step = 1:steps
% Check for Cancel button press
if getappdata(h,'canceling')
break
end
% Report current estimate in the waitbar's message field
waitbar(step/steps,h,sprintf('%12.9f',valueofpi))
% Update the estimate
pisqover8 = pisqover8 + 1 / (denom * denom);
denom = denom + 2;
valueofpi = sqrt(8 * pisqover8);
end
delete(h) % DELETE the waitbar; don't try to CLOSE it.
I use the function approxpi(…) as a callback of another button (name it A) , and it still works! but how?
In "Control Callback Excution and Interuption",it says:
"If a callback is executing and the user triggers an event for which a callback is defined, that callback attempts to interrupt the callback that is already executing. When this occurs, MATLAB software processes the callbacks according to the values of two properties:
The Interruptible property of the object whose callback is already executing. The Interruptible property specifies whether the executing callback can be interrupted. The default value for uicontrol objects is 'on', allowing interruption.
The BusyAction property of the object whose callback has just been triggered and is about to execute. The BusyAction property specifies whether to queue the callback to await execution or cancel the callback. The default property value is 'queue'. "
so ,with the sample code above ,when i click the cancel button of the waitbar, there is already callback running ,so the 'setappdata(gcbf,…)' should have be canceled,and as a result the cancel button should have not worked.
I get confused

Best Answer

It is allowed for one handle graphics callback to interrupt another, provided that the Interruptible and BusyAction properties agree.
Note: waitbar() creates a new figure with its own properties.
Related Question