OnScheduledTimer getting called 1 second before due

OnScheduledTimer() event handler is getting called before it is due (exactly 1 second), the attached logs show me setting an 8am timer at 07:53, the event handler then sets the next timer on the next hour when 8am is reached - so at 8am the next timer should be 9am, but because the timer is getting called earlier than set, the handler is repeatedly called until the actual set time is reached.
Script Output.txt (6.5 KB)
the error is fixable if SetScheduledTimer() is set 1 second ahead.

  • please fix :slight_smile:

Instead of the output text file, how about providing the script, to make it easier for us to try it?

it is a simple reminder - shows a dialog every interval hours (config) from an anchor hour(config).
set

  • log level to 2
  • interval to 1
  • anchor to 12

it runs continuously (the script ends but SetScheduledTimer() is set again in OnScheduledTimer()) when started with Reminder START using the settings set in script configuration which defaults to every day at noon.
can be stopped and all variables and timers deleted with Reminder STOP
minimum interval is 1 hour, which means debugging can be a lengthy process.
The SetScheduledTimer() is set at line 396 (DO script editor)
if line 390 is changed to 1 second the error does not happen (EDIT: error still happens because it is 1 second out at your end).
OnScheduledTimer() event handler is at line 178.
Work in progress, will probably post it when finished.
Reminder.opusscriptinstall (16.3 MB)

1 Like

It seems that surprisingly galaxyhub has a point here. It's easily reproducible using the 'cmd2' command attached below.
cmd2.opusscriptinstall (1.1 KB)


The difference is less than a second, though. Tbh, I use scheduler timers daily but never noticed the less-than-a-second difference.

1 Like

The new beta makes these timers more accurate.

(The problem was because timers in Windows aren’t very accurate. We’ve made Opus deal with that so scripts don’t have to.)

1 Like

Awesome - fixed now
-first log at +6 milliseconds (time taken to display the log entry ?)
-second log at +7 milliseconds
many thanks :slight_smile:

1 Like