v1 wrote:If Period is negative,
v2 wrote:If Period is less than 0,
iseahound wrote:how did -0 end up queuing² the next routine in v1?
The premise of your question is mistaken. As I said at the beginning, timer subroutines do not execute immediately after SetTimer,
except by coincidence.
Code: Select all
#requires AutoHotkey v1
SetTimer tick, -0
Loop
x := A_Index
tick:
MsgBox % x
ExitApp
For me, there are anywhere between 20,000 and 150,000 iterations before the timer executes.
² Or perhaps jumping the queue
They do not. If there are two timers, to be fired at
n+0 and
n+15, and the timers are checked at tick =
n, obviously only the
n+0 timer will fire. If the timers are checked at tick =
n+16, the timers will fire in the order they were added to the list. There is no queue.
All timers are checked and executed by CheckScriptTimers(), which is called upon entry to MsgSleep() or when a WM_TIMER message with a null lParam is received by the main window. Unless you call the Win32 SetTimer(), this only occurs for the timer set by SET_MAIN_TIMER, which sets an interval of
10. The resolution of these timers is probably more like 15.6 milliseconds, as mentioned in the documentation. Even if the timers are checked due to MsgSleep() calls more often than the resolution of Win32 SetTimer(), GetTickCount() is used to determine when the script timers should execute. GetTickCount() can be observed to have an average resolution of 15.6 milliseconds under normal conditions.
A timer period of 0 would allow the timer to execute within the same tick as the call to SetTimer, whereas a non-zero period would require the tick count to change. Even under ideal conditions, the tick count could change anywhere between 0 and 16 milliseconds after SetTimer is called.