Too Many Timers Error

Hi all,

I am getting this error when running an app in the sim - but it works fine on my FR235: 

Failed invoking <symbol>
Too Many Timers Error

I have 4 timers running and the behaviour is slightly different depending on the scenario:

1) timer counting up each second

countup.start( method(:countupTimerCallback), 1000, true );

2) timer counting down each second

countdown.start( method(:countdownTimerCallback), 1000, true )

3) timer checking if the countdown timer is (still) paused after 5 seconds

pausedTimer.start(method(:pausedTimerCallback), 5000, true);

4) timer checking if exit pressed 3 times within 3 seconds (non-repeating timer)

exitTimer.start(method(:exitTimerCallback), 3000, false);

If I have 1 and 2 running I can call timer 4 and it all works fine

If I have 1,2 and 3 running then I get the error when trying to call 4

Can you have more than 3 timers running at the same time?

  • 3 is the max.  The best way to handle this is to have one timer, and let it handle the various things.  Have a timer for seconds, and let it look for things at 3 seconds, 5 seconds, etc.  If you're looking for "time between" things, you can always use Sys.getTimer() (it's milliseconds) or Time.now().value() (time since jan 1,1970 in seconds)

  • https://developer.garmin.com/downloads/connect-iq/monkey-c/doc/Toybox/Timer/Timer.html

    "The number of available timers (default 3) and the minimum time value (default 50 ms) depends on the host system. An error will occur if too many timers are set."

    I don't know much about your app, but I feel like at least 3) could be done without a timer. The way I would do it:

    - when exit (Back?) is pressed for first time, record the value of System.getTimer() (which is actually just the uptime in milliseconds)

    - the 3rd time exit is pressed, call System.getTimer() again and compare with the recorded value above

    As Jim said, it would probably be best if you can do everything with one timer. This may not be possible if you need sub-1 second precision, but like I said, I don't know much about your app.
    Also, I would prefer System.getTimer() over Time.now() when calculating the duration between two things, because Time.now() gives you the clock time which can change unexpectedly (although this would admittedly be a very rare edge case). System.getTimer() wraps, but it doesn't matter if you're only ever calculating the difference between two values.
  • Ah, the good old RTFM. :) Thank you for that, I should have looked it up myself first. 

    I've been a bit lazy in just creating a new timer when testing functionality rather than re-using the timer object but you are absolutely right, this could all be done in one timer.

    Very helpful, thank you.

  • I can't think of any app I've done with more than 1 timer.  I usually have one that fires every second, and it's used for updating the display, displaying popup messages, vibrating after a certain amount of time when recording is paused, saving the current location to display a breadcrumb trail, getting data from "off watch" (a sensor or the internet), etc.