- Interrupt Callback Execution: https://www.mathworks.com/help/matlab/creating_guis/interrupt-callback-execution.html
- Timer: https://www.mathworks.com/help/matlab/ref/timer.html
Property with set observable attribute interrupts a current running callback when triggered
4 ビュー (過去 30 日間)
古いコメントを表示
I have a drop down callback, which is actioned when the user selects one of the many options. Then this callback is triggered, but along the callback there is a code line where an app.property is assigned a new value, this property has as one of its attributes, the Set observable activated, then the code interrupts the first callback and move to run the listener callback of this app.property. Once this second callback (the listener callback) is finished, Matlab comes back to the earlier callback. But the thing is that I don't want this to happen, cause the listener callbacks needs something from the first callback which is placed below the line of the property with the Setobservable atribute.
I have set, for the drop down callback, the "Interruptible property" to "off", and the "Busyactions property" to "cancel" as the Matlab documentation suggest (Matlab app designer pdf - page 11-15), but nothing happens.
Any idea what to do with this? I have googled this issue before to look for a similar one and nothing, that is why I rise this question.
0 件のコメント
回答 (1 件)
Abhishek Chakram
2024 年 4 月 23 日
Hi LEMF,
The behaviour you are experiencing is due to the “SetObservable” property triggering its listener callback immediately upon assignment, which can indeed interrupt the flow of the initial callback function. To overcome this, you can set the “BusyAction” property to “queue” as this tells MATLAB to execute the interrupting callback after the running callback finishes. The “Interruptible” property will be set to “off”.
Alternatively, you can also defer the execution of the property change that triggers the listener by using a timer or by scheduling the change to occur after the current callback finishes its critical section. Here is a simple example using a timer:
% Inside your dropdown callback
function dropdownCallback(app, event)
% Your initial callback code here
% Defer the property assignment
t = timer;
t.StartDelay = 0.01; % Delay in seconds, adjust as needed
t.TimerFcn = @(~,~) setProperty(app);
start(t);
end
% Separate function to change the property
function setProperty(app)
app.YourObservableProperty = newValue; % YourObservableProperty is your property
end
You can refer to the following documentation to know more about functions used:
Best Regards,
Abhishek Chakram
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!