Stop/Delete Timer Issues While Closing GUI
Hi,
I use a timer to update an axes in a GUI. I want to handle the case in which the user closes the window while the timer is still running, i.e., the axes still beeing updated.
The Problem:
However, every so often the execution time of the TimerFcn is longer than the timers period (depending on the pc’s performance). This can cause an error when closing the GUI while the timer is still running.
Error while evaluating TimerFcn for timer ‘timer-1’
Bad handle
FYI, I use
T = timerfind;
if ~isempty(T)
stop(T)
delete(T)
end
in the figure’s delete function. Apparently, the TimerFcn is still being called after the execution of the figure’s delete function. Hence, within my TimerFcn an error occurs during a call to
cla(myaxes),
for cla expects a valid figure handle (though the GUI’s figure has just been deleted).
All in all, it seems that the execution time being larger than the timer period is causing this. Of course I could reduce the timer period, but this is not desirable. I figured out a workaround by using a try-catch phrase within the TimerFcn, however it’s not a proper solution.
Question:
Is there any way to force the TimerFcn to stop and somehow flush its executin queue/event buffer, regardless of its current state? Any thoughts about solving this issue are very welcome!
Thank you in advance!
HannesHi,
I use a timer to update an axes in a GUI. I want to handle the case in which the user closes the window while the timer is still running, i.e., the axes still beeing updated.
The Problem:
However, every so often the execution time of the TimerFcn is longer than the timers period (depending on the pc’s performance). This can cause an error when closing the GUI while the timer is still running.
Error while evaluating TimerFcn for timer ‘timer-1’
Bad handle
FYI, I use
T = timerfind;
if ~isempty(T)
stop(T)
delete(T)
end
in the figure’s delete function. Apparently, the TimerFcn is still being called after the execution of the figure’s delete function. Hence, within my TimerFcn an error occurs during a call to
cla(myaxes),
for cla expects a valid figure handle (though the GUI’s figure has just been deleted).
All in all, it seems that the execution time being larger than the timer period is causing this. Of course I could reduce the timer period, but this is not desirable. I figured out a workaround by using a try-catch phrase within the TimerFcn, however it’s not a proper solution.
Question:
Is there any way to force the TimerFcn to stop and somehow flush its executin queue/event buffer, regardless of its current state? Any thoughts about solving this issue are very welcome!
Thank you in advance!
Hannes Hi,
I use a timer to update an axes in a GUI. I want to handle the case in which the user closes the window while the timer is still running, i.e., the axes still beeing updated.
The Problem:
However, every so often the execution time of the TimerFcn is longer than the timers period (depending on the pc’s performance). This can cause an error when closing the GUI while the timer is still running.
Error while evaluating TimerFcn for timer ‘timer-1’
Bad handle
FYI, I use
T = timerfind;
if ~isempty(T)
stop(T)
delete(T)
end
in the figure’s delete function. Apparently, the TimerFcn is still being called after the execution of the figure’s delete function. Hence, within my TimerFcn an error occurs during a call to
cla(myaxes),
for cla expects a valid figure handle (though the GUI’s figure has just been deleted).
All in all, it seems that the execution time being larger than the timer period is causing this. Of course I could reduce the timer period, but this is not desirable. I figured out a workaround by using a try-catch phrase within the TimerFcn, however it’s not a proper solution.
Question:
Is there any way to force the TimerFcn to stop and somehow flush its executin queue/event buffer, regardless of its current state? Any thoughts about solving this issue are very welcome!
Thank you in advance!
Hannes timer, closing gui MATLAB Answers — New Questions