Named Timers

Post Reply
boingy
Posts: 11
Joined: Sun Jun 05, 2022 12:21 pm

Named Timers

Post 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. :?:
User avatar
seal58
Posts: 377
Joined: Fri Jul 12, 2019 5:28 pm
Location: Rostock, Germany
Contact:

Re: Named Timers

Post 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;
User avatar
TheGarnet
Posts: 38
Joined: Mon Aug 22, 2022 1:55 pm

Re: Named Timers

Post 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.
Post Reply

Return to “Module Designer”