What happens to a timer action when it can't fire on time

Does anyone know off hand what happens when a timer cant trigger on time because of a tight loop or some other reason? Does it trigger when it can even if it’s much later? Or does it skip it and wait for the next time to roll around? Is the answer different if it’s in single or multiple run mode?

Let’s say that I make a single run mode timer for 50 milliseconds, and then start a tight loop that lasts 480 milliseconds. When the tight loop ends does it immediately fire the timer action? It’s 430 milliseconds late. Or does it skip it because it’s too late.

If it was a multiple run mode timer, it should have fired 9 times during that tight loop but couldn’t. So…

  1. Does the timer fire immediatly, even though the next 50 millisecond block would be at 20 milliseconds later? Or does it wait until the next time the timer hits?

  2. What happens to all the other ones it missed? Does the timer attempt to fire 9 times immediately or to catch up on all the missing firings? If it got a couple in but not all 8 missing ones before the next one hits, will it fire the new 50ms one and then continue trying to catch up the missing ones? Not that the order would matter in this case. Still wondering.

OR will it only fire once because it only tracks the most recent clocked one?

I’m about to do a test of these but was wondering if anyone knows off the top of their head from experience.

I suspect this question will make some people’s neck hairs stand on end… “Don’t use tight loops!” :smile: I know what I’m doing. Just breathe… it’s ok… breathe…

Think of the Period as “no sooner than”. The Timer will fire at its next opportunity, then reset to wait out the Period and fire at the next slot thereafter.

In your scenario, it will fire after your tight loop finishes, then sometime after 50 ms when the main thread of your app is otherwise idle.



Yeah I did a test and it performs as I would want it to:

Update: 8 Time: 1137461430080.708984 Dur: 1000848.888916
Update: 9 Time: 1137462430684.983887 Dur: 1000604.274902
Update: 10 Time: 1137463431032.179932 Dur: 1000347.196045
Update: 11 Time: 1137464431135.429932 Dur: 1000103.250000
TimerTest Start: 1137464547051.175049 Dur From last trigger: 115915.745117
TimerTest End (5.5 sec later): 1137470048735.187988 Dur From last trigger: 5617599.758057
Update: 12 Time: 1137470050078.854980 Dur: 5618943.425049
Update: 13 Time: 1137471050697.354004 Dur: 1000618.499023
Update: 14 Time: 1137472051432.853027 Dur: 1000735.499023
Update: 15 Time: 1137473052504.310059 Dur: 1001071.457031

So I think all the missed firings casued it to just fire once as soon as it could. And then the rest just got on track from there. So this will work nicely for what I need it to do. Thanks again!

I think it’s logic as it is now. But it has not been always the case. It was like that very long time ago, but it changed during a time. Some years ago I wrote a feedback or here in the forum that a Timer fire while the main Thread was busy (not a Thread from the IDE). And I’m nearly sure that Kem answered to leave it as it was.
I have to find the discussion.
But just keep in mind that it may change again.

Edit: What I wrote above may be wrong. It seems that I have a DialogBox change the way it runs. I think it is this forum thread.