Can't restart timer

Former Member
Former Member
If I call

mTimer.stop();
mTimer.start(.....

the timer won't run. So I have no way of preventing a too many timers error, because simply calling start() again can start another instance despite using the (supposedly) same object.
  • Former Member
    Former Member over 10 years ago
    I have discovered that this behavior is particular to a non-repeating timer. eg mTimer(method(:doSometin),60000,false); I can stop and start a repeating timer.
  • Former Member
    Former Member over 10 years ago
    ...look, I don't know. But this doesn't continue to run, and I think it should

    function doFunc()
    {
    mUpdateTimer.stop();
    mUpdateTimer.start(method(:doFunc),1000,false);
    System.println("Doing func");
    }
  • I'll look at this, see if I can reproduce, and get it reported.
  • ...look, I don't know. But this doesn't continue to run, and I think it should

    function doFunc()
    {
    mUpdateTimer.stop();
    mUpdateTimer.start(method(:doFunc),1000,false);
    System.println("Doing func");
    }


    This looks like you're trying to create a repeating timer out of a non-repeating timer. :) I was able to basically reproduce what you're seeing. If the stop() call is removed, this amazingly continues to run (I half suspected there would be some kind of recursive nightmare, but in the simulator at least, it's happy to chug along with no issue). With the stop(), it executes doFunc() twice, and then ends. This isn't so clear to me, and I'm not certain what the expected behavior is in this case. My guess is that it's related to the way the timer actually executes and how one of the stop() calls lines up with the execution.

    I've spent a while this afternoon experimenting with some different code snippets and wasn't able to divine what's happening, so I'll pass it on for a deeper investigation into the virtual machine code.

    Out of curiosity, what are you trying to accomplish with this?
  • Former Member
    Former Member over 10 years ago
    I was trying to achieve state change. I would call a new state (represented by a function, eg doFunc in the example). That state would then take control of the timer, and close any existing instance from another state.
  • Scenario
    * certain event is supposed to fire up backlight
    * backlight has to turn off after n seconds
    * Trigger event can occure more than once within the n seconds time span

    Looks similar to the Scenario described by you. First implmentations showed similiar phenomena/problems.
    The following schematics tries to expose the essentials of the code that finally did the trick:
    function initialize() {
    ...
    // the "other" timer / event timer
    updateTimer = new Timer.Timer();

    lightOffTimer = new Timer.Timer();
    }
    ...
    // event uses this function to turn backlight on
    function lightOn() {
    Attn.backlight(true);

    lightOffTimer.stop();
    lightOffTimer.start(method(:onBackLightTimer), backLightSeconds*1000, false);
    }
    ...
    function onBackLightTimer() {
    Attn.backlight(false);
    System.println("OFF");
    }

    So, in essence, the timer will be stopped only upon intention of restart. This code has been tested sucessfully on a F3.
  • Former Member
    Former Member over 10 years ago
    Same same but different. The subtlety being that yours does not need recursion. My biggest problem was that I was having "too many timers". I maintain that programmatically I wasn't, but I could force the error with lots of screen switching and strange behaviors and so on. I'm in the process of experimenting with global timers, which should hopefully mean it can't open more than 3. 3 timers is the limit.
  • I ran in to this exact issue.

    The solution I went with was to have a single master timer across the application that is only started once (when the app starts) and stopped once (when the app stops).

    Anything that needs timing registers itself with the master timer once and will receive onTick() events from then to eternity. Whether they choose to act on the event depends on their own internal state which they keep track of.

    So far this approach has worked well and I no longer see any `TooManyTimer` exceptions.
  • The originally reported issue has bee addressed, and the fix will be available in an upcoming SDK release.