Thread Subject: Deleting timers from within their StopFcn

Subject: Deleting timers from within their StopFcn

From: Kenneth Eaton

Date: 5 Dec, 2008 20:55:06

Message: 1 of 2

Looking over the examples The MathWorks gives for using timers, I noticed that they are always deleted after being used (a good practice). However, I was curious if you could just delete a timer from within it's own StopFcn, so that it would delete itself upon completing its task. I tested it a few times and it seems to work just fine.

Since I've never seen an example of this being done, I was just curious if anyone knew of any unforeseen reason why this would be a bad thing to do?

Ken

Subject: Deleting timers from within their StopFcn

From: Kenneth Eaton

Date: 5 Dec, 2008 21:13:03

Message: 2 of 2

Never mind... I just found a situation where things go wrong. If you are in a situation where a program is waiting for a timer to complete, you get an error. Here is an example:

>> ht=timer('ExecutionMode','fixedRate','Period',1,'TasksToExecute',10,...
'TimerFcn','disp(''tick'');','StopFcn','delete(ht)');
>> start(ht); wait(ht);
tick
tick
tick
tick
tick
tick
tick
tick
tick
tick
??? No appropriate method or public field isRunning for class handle.

Error in ==> timer.wait at 46
    end

In this case, I would have to delete the timer after the WAIT command.

Ken

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
timer Kenneth Eaton 5 Dec, 2008 15:55:08
delete Kenneth Eaton 5 Dec, 2008 15:55:08
stopfcn Kenneth Eaton 5 Dec, 2008 15:55:08
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com