I've got an AutoHotkey script that presents the following error when I try to run it again:
Could not close the previous instance of this script. Keep waiting?
It's a pretty simple script, with the following settings:
#NoEnv
#SingleInstance force
SendMode Input
DetectHiddenWindows, on
SetWinDelay, -1
I'm launching the script from the command line. I've tried using the /f
/ /force
option and there is no effect.
I want the #SingleInstance Force
behaviour described in the docs, which is described as:
Skips the dialog box and replaces the old instance automatically, which is similar in effect to the Reload command.
Turns out the problem was the SetWinDelay
instruction.
From the docs:
Although a delay of -1 (no delay at all) is allowed, it is recommended that at least 0 be used, to increase confidence that the script will run correctly even when the CPU is under load.
A delay of 0 internally executes a Sleep(0), which yields the remainder of the script's timeslice to any other process that may need it. If there is none, Sleep(0) will not sleep at all.
When I had it set to -1
the script never had time to process other commands, including whatever exit command was sent to it.
Ensure SetWinDelay
is greater than or equal to 0.