In app designer the timer call back keeps running after xing out of application.

4 views (last 30 days)
The timer object is created and started with the code at startup:
% Code that executes after component creation
function startupFcn(app)
%Creating timer object
t=timer('TimerFcn',@app.TimerCallback,...
'ExecutionMode','fixedRate',...
'Period',1.0,...
'TasksToExecute',Inf);
%Start timer
start(t);
tic;
end
My TimerCallback function is:
function TimerCallback(app, obj, event, string_arg)
toc;
end
So, how can I run delete(t) to delete the timer object so that is stops running? It there a tear down function where I can insert this delete instruction?
The only way I get it to stop is by exiting app designer. Otherwise, it keeps creating more and more instances of the timer and runs them all!

Answers (1)

VBBV
VBBV on 21 Jun 2023
can you try placing the delete(t) inside the timercallback function ?
function startupFcn(app)
%Creating timer object
t=timer('TimerFcn',@app.TimerCallback,...
'ExecutionMode','fixedRate',...
'Period',1.0,...
'TasksToExecute',Inf);
%Start timer
start(t);
tic;
end
function TimerCallback(app, obj, event, string_arg)
toc;
% insert after toc
delete(t)
end

Categories

Find more on Develop Apps Using App Designer 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!