Page 1 of 1
Named Timers
Posted: Sat Jun 11, 2022 3:36 pm
by boingy
I've just been trying to use a NamedTimer for the first time and it seems to have slightly odd behaviour. It looks like it triggers a Notify event immediately and then settles into the regular time period I've set.
So if, for example, I set it for 1000 ms, I get the first notification in less than a millisecond and then regular one second ticks after that.
Is that a bug or deliberate functionality?
I can't think why you would ever want a timer to behave like that.
Re: Named Timers
Posted: Thu Jul 28, 2022 8:35 am
by seal58
That's normal behaviour.
When named timer is initallized by VM system, it fires first time and sends a message to Notify().
I use a boolean marker 'timerStarting' to solve that. I set it to TRUE after StartNamedTimer().
So my code in Notify() is:
Code: Select all
case Named_Timer:
{
String tn = (String) object;
if ( tn.equals ( timername )
{
if ( timerStarting )
timerStarting = false; // no action, because timer has fired first time
else
{
// regular timer action
}
}
}
break;
Re: Named Timers
Posted: Tue Nov 29, 2022 4:45 pm
by TheGarnet
I just wasted a couple of hours figuring this out. And blaming myself at each step, mostly thinking I didn't understand the durations.
The documentation doesn't mention this quirk.
The way this is now, the above is necessary on every named timer. It must be replicated for every named timer you need.
I think the named timer event notification should include longValue being set to the number of times the timer has fired since starting, with the initial firing being 0.