<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240527</link>
    <title>MATLAB Central Newsreader - Deleting timers from within their StopFcn</title>
    <description>Feed for thread: Deleting timers from within their StopFcn</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 05 Dec 2008 20:55:06 -0500</pubDate>
      <title>Deleting timers from within their StopFcn</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240527#615358</link>
      <author>Kenneth Eaton</author>
      <description>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.&lt;br&gt;
&lt;br&gt;
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?&lt;br&gt;
&lt;br&gt;
Ken</description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 21:13:03 -0500</pubDate>
      <title>Re: Deleting timers from within their StopFcn</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240527#615362</link>
      <author>Kenneth Eaton</author>
      <description>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:&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; ht=timer('ExecutionMode','fixedRate','Period',1,'TasksToExecute',10,...&lt;br&gt;
'TimerFcn','disp(''tick'');','StopFcn','delete(ht)');&lt;br&gt;
&amp;gt;&amp;gt; start(ht); wait(ht);&lt;br&gt;
tick&lt;br&gt;
tick&lt;br&gt;
tick&lt;br&gt;
tick&lt;br&gt;
tick&lt;br&gt;
tick&lt;br&gt;
tick&lt;br&gt;
tick&lt;br&gt;
tick&lt;br&gt;
tick&lt;br&gt;
??? No appropriate method or public field isRunning for class handle.&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; timer.wait at 46&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&lt;br&gt;
In this case, I would have to delete the timer after the WAIT command.&lt;br&gt;
&lt;br&gt;
Ken</description>
    </item>
  </channel>
</rss>

