Effacer les filtres
Effacer les filtres

Deleting Timer Objects containing in Objects' properties

4 vues (au cours des 30 derniers jours)
Bolivar
Bolivar le 10 Juil 2013
Hello,
ich have been trying to delete Timer Object, stored in Object's property before destroying the concerned object. But the Object is deleted and the Timer not. Then any try to delete the timers with help of built-in function "delete" cause matlab to crash. I'm using the following code:
properties
timerCall
end
the Timers' parameter are initialized in constructor. The delete function look like this:
methods
function delete(obj)
delete(obj.timerCall);
end
end
What am I doing wrong? can someone help me?
thanks

Réponse acceptée

Image Analyst
Image Analyst le 10 Juil 2013
See if my code to kill all timers works for you:
%--------------------------------------------------------------------------------------------------------------------------
function StopTimer(handles)
try
fprintf('Entering StopTimer...\n');
listOfTimers = timerfindall % List all timers, just for info.
% Get handle to the one timer that we should have.
if isempty(listOfTimers)
% Exit if there is no timer to turn off.
fprintf('There are no timers to turn off. Leaving StopTimer().\n');
return;
end
handleToTimer = getappdata(handles.figMainWindow, 'timerObj');
% Stop that timer.
stop(handleToTimer);
% Delete all timers from memory.
listOfTimers = timerfindall
if ~isempty(listOfTimers)
delete(listOfTimers(:));
end
fprintf('Left StopTimer and turned off all timers.\n');
catch ME
errorMessage = sprintf('Error in StopTimer().\nThe error reported by MATLAB is:\n\n%s', ME.message);
fprintf('%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
return; % from btnStopTimer_Callback

Plus de réponses (1)

Bolivar
Bolivar le 24 Juil 2013
Hi, your code works properly. In fact it's excellent. But, I made the mistake using lots of handle in my programm, which was paced amoong different user. Moreover I didn't delete timers after they 've expired what i should after the documentation. Wherefore my problem. Nevertheless I've manage to solve this. Anyway thanks for your support

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by