#SingleInstance Force - does not work 100% of time

Get help with using AutoHotkey and its commands and hotkeys
Posts: 53
Joined: 30 Sep 2013, 21:33

#SingleInstance Force - does not work 100% of time

03 Jan 2014, 11:50

Hey guys,

'#SingleInstance Force' does not work all the time. I have some scripts where it is within the main loop, so it should definitely be working I would think.

Is there any way to get it to work flawlessly?
User avatar
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: #SingleInstance Force - does not work 100% of time

03 Jan 2014, 13:14

Add #SingleInstance Force to the top of your script, not inside a loop.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
Posts: 6878
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: #SingleInstance Force - does not work 100% of time

03 Jan 2014, 17:42

It makes no difference where you put it.

There are two ways it can fail:
  1. It fails to find the previous instance's main window (which is usually hidden). This will happen if you changed the window's title (WinSetTitle) or parent (DllCall to SetParent). It can also happen if you launch the script using a different path; for instance, if you launch the script from a mapped network drive and then from a UNC or local path, they won't be considered the same script.
  2. It fails to close the other window because the window is not responding to messages, or the script specifically discards the WM_COMMNOTIFY message. If closing the script fails, you get an error message to that effect.
As far as I can tell, it is not possible for #SingleInstance to fail any other way.

I wouldn't call it a failure, but having #SingleInstance Off after it in the script would stop it from working. For instance,

Code: Select all

if something
    #SingleInstance Force
    #SingleInstance Off
In this case, the setting is unconditionally OFF, because as I said, it makes no difference where you put the directive. It takes effect immediately upon loading the script, before the script starts executing (so before if-statements etc. can be evaluated).
User avatar
Posts: 877
Joined: 12 May 2015, 02:10
GitHub: sl5net

Re: #SingleInstance Force - does not work 100% of time

26 Apr 2017, 13:24

; thats the plan:
; SingleInstance,Force ... but its sometimes not work. See reasons above.
; set NoTrayIcon to make it hidden.
; Search it. hopefully dont find it. if its found, then dont start it again as a second instance.
good luck :-)

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, ajhauk, boiler, Google [Bot], hamilbody, Ian and 251 guests