Descolada wrote: ↑26 Mar 2024, 04:37
F3 sends the string fewer times because otherwise the script would run too long (because of the halting).
Conversely, if there's no halting, F3 will complete faster. Why send so many keystrokes in F2? Better to write it so that the
expected results are the same for both. Then you can say that F3 should behave the same as F2, but for you it is much slower. Anyone can easily see that there is a difference (issue replicated), or no difference (issue not replicated).
... wouldn't interrupt other running threads unexpectedly.
Perhaps it would meet that condition, but not in any meaningful way. It would expectedly interrupt the HandleWinEvent function, which itself was an "emergency" and has already interrupted the running thread (but not started a new thread, because of Fast mode). Whatever other threads that were interrupted still can't resume til the new thread you launched finishes. At least the timer thread would not affect the settings of whatever thread HandleWinEvent interrupted.
If you want to make a new "thread" happen immediately and without risk of side-effects (like dispatching other messages), the best way is to call a callback (CallbackCreate and DllCall). There is no need to make the current thread non-Critical in that case.
Using OnMessage and SendMessage would come close, but there is more hidden complexity, and the current thread priority must be <= 0. SendMessage calls the window procedure directly if the window is owned by the same (real) thread as the caller, but I'm uncertain whether there can still be other side-effects (e.g. dispatching externally sent messages, as it does when waiting for a reply from another thread).
This result is surprising, I would've expected the same result as test 1 (no halting).
Critical being on causes some messages to be "buffered" (left in the queue), as its main effect. As documented,
Critical "Off" makes the current thread
immediately interruptible, regardless of whether the thread's default period of uninterruptibility has expired.
Descolada wrote:It seems Sleep -1 (force message check) trumps Critical -1 (disable message checks)
The documentation is explicit about what the numeric parameter of Critical does and does not affect.
However, functions that wait such as Sleep and WinWait will check messages regardless of this setting ...
This setting affects the following:
- Preemptive message checks, which potentially occur before each line of code executes.
- Periodic message checks during Send, file and download operations.
It does not affect the frequency of message checks while the script is paused or waiting.
...
Critical -1 turns on Critical but disables message checks. This does not prevent the program from checking for messages while performing a sleep, delay or wait.
Source: Critical - Syntax & Usage | AutoHotkey v2
"Critical -1" was
added to the documentation in 2023, as a newly
discovered feature.
It is really just a consequence of (UINT)-1 producing the maximum value for UINT, the same as
Critical 4294967295. In order for an automatic message check to occur, the tick count (milliseconds as an unsigned 32-bit integer) since the last check must be
greater than the period specified by Critical. Even if the program could go that long without a message check (such as due to the computer being asleep for weeks), the interval can't be reached because there is no 32-bit integer greater than (UINT)-1.
There was no halting with any of the [TestGui] tests!
Notepad is more than just an Edit control. What is the callback notifying you about?