필터 지우기
필터 지우기

Deleting Timer Objects containing in Objects' properties

조회 수: 4 (최근 30일)
Bolivar
Bolivar 2013년 7월 10일
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

채택된 답변

Image Analyst
Image Analyst 2013년 7월 10일
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

추가 답변 (1개)

Bolivar
Bolivar 2013년 7월 24일
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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by