How do I make a function which is not a GUI callback uninterruptible?
Show older comments
I am running a GUI based asynchronous code. I have some functions that are called in the code but are not direct callbacks of any GUI object, but are called by events and timers. I would like to make sure that one of these functions is not interrupted by any of the others and that all other functions will be queued until this one has finished.
1 Comment
Rik
on 15 Jul 2018
The queuing bit is not trivial. I generally only have situations where I need to reject new function calls. To do that, you can use the appdata to store a busy flag (which you can even set to the groot instead of a figure):
setappdata(groot,'LongNameToAvoidConflicts',1)
But that doesn't really help you in queuing.
Answers (1)
Here is an idea (untested, but it might work): define a simple GUI object (e.g. a uicontrol push button) that calls the uninterruptible functions. Set its 'Interruptible' and 'Visible' properties to 'off'. When you want to run the uninterruptible function, get the timer/... to change some property of the object (e.g. the value). This will trigger the callback, which hopefully then runs without interruption....
If that does not work then do the same with a listener:
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!