Multithreading is based on AutoHotkey.dll (only AutoHotkey.dll 1.0.48.3 is supported at the moment).
Thread function will help you to use multithreading.
Thread([file_or_text,parameters,dllpath])
| Parameter | Info |
| file_or_text | Thread can execute files as well as text. So this parameter can be a file path or text. |
| parameters | You can pass on parameters to your thread as usual. |
| dllpath | Path of AutoHotkey.dll. |
A thread can also exit itself (like ExitApp in AutoHotkey) using DllCall("ExitThread","Uint",0)
When checking for Thread, return value will be 1 if it exist 0 if not and 259 if it is still active. ErrorLevel will contain exit code of the thread if it still exist.
Read about Multithreading Consideration and Terminate Thread on MSDN
None.
#NoEnv
var(1="",2="",3=""){ ;declare dictionaryfunction
}
OnMessage(0x9999,"ExitThread")
Gui, +LastFound
hwnd:=WinExist()
DDB()
Script=
(LTrim`t
#NoEnv
#NoTrayIcon
DetectHiddenWindows,On
var(1="",2="",3=""){ ;you need to declare the same dictionaryfunction again to use it!!!
}
DDB()
SetBatchLines,3
Loop
var(1, A_TickCount)
ExitApp
e::SendMessage,0x9999,A_Thread,,,ahk_id %hwnd% ;A_Thread and #Persistent are added to top of script when calling Thread()
#Include %A_ScriptDir%\DDB.ahk
)
threadID:=Thread(script) ;start new thread
lib:=ErrorLevel
Thread(threadID,1,-15) ;change threads priority
SetTimer,ToggleSuspend,1000
SetBatchLines,10
count=1
Loop
ToolTip % "A_TickCount is set in a separate thread.`nMain process displays this ToolTip + pauses and resumes the thread each second.`nPress Esc to exit`nPress e to exit/kill thread (you can start a new one by pressing n)`nThreadcount: " count "`n`n" var(1)
~Escape::
Exit:
Thread(threadID,0) ;kill thread (not really required)
DDB()
ExitApp
n::
Thread(threadID,0,lib)
threadID:=Thread(script) ;start new thread
Thread(threadID,1,-15) ;change threads priority
count++
Return
ToggleSuspend:
If (suspended:=!suspended)
Thread(threadID,2) ;suspend thread
else
Thread(threadID,3) ;resume thread
Return
ExitThread(wParam){
global
Thread(wParam,0,lib)
}
#include %A_ScriptDir%\DDB.ahk
#include %A_ScriptDir%\Thread.ahk