DAS Timer Event, Wait and Time Boundaries
Use short callbacks, explicit enablement and midnight-safe observation intervals.
Scheduling is different from waiting
Prerequisite: shared state and helper contracts. The reviewed guide describes a Timer Event running every second. Wait(milliseconds) pauses script continuation; it is not a Promise, a broker acknowledgement or proof another action completed. A while loop with Wait is explicitly discouraged as a timer substitute. Use short callbacks and separate the question "when should I inspect?" from "what state did I observe?"
Initialize before enabling the callback
Clear/disable the Timer Event while installing this practice. Run the initializer manually, then install the callback below. It only updates counters and times; it does not display a popup every second or submit anything.
Initializer
$feClock = NewUserObj();
$feClock.enabled = 1;
$feClock.interval = 5;
$feClock.lastSecond = GetSecond();
$feClock.samples = 0;
Timer Event body
if ($feClock.enabled == 0) {
return;
}
$feNow = GetSecond();
if ($feNow < $feClock.lastSecond) {
$feClock.lastSecond = $feNow;
return;
}
if (($feNow - $feClock.lastSecond) >= $feClock.interval) {
$feClock.lastSecond = $feNow;
$feClock.samples = $feClock.samples + 1;
}
Explain the timing policy
GetSecond counts seconds since midnight, not Unix time. When the clock moves backward, the callback resets its observation baseline and skips work. Otherwise it increments at most once per callback when five seconds have elapsed. A delayed callback does not replay every missed interval: this is a skip-missed-samples policy. It is not a real-time scheduler and does not establish exchange or broker time. Clock changes and midnight need explicit tests.
Observe and stop
MsgBox($feClock.samples, $feClock.lastSecond);
$feClock.enabled = 0;
Exercise and worked answer
Suppose lastSecond=100, interval=5 and callbacks arrive at 102,105,117. Answer: no increment at 102, one at 105, one at 117. Missing 110 and 115 does not cause two catch-up actions. If lastSecond=86399 and now=2, reset baseline to 2 with no increment. To uninstall, disable the callback in DAS before deleting $feClock; the enabled flag cannot protect a missing object.