NewThread

Create a real additional AutoHotkey thread in current process without using AutoHotkey.dll (based on NewThread).


OutputVar := NewThread(Script , Parameters, Title, Wait, Library)
Command  Example: NewThread "MsgBox Message from thread."
Function Example: Thread := NewThread("MsgBox Message from thread.")

Parameters

OutputVar

The name of the variable in which to store the Thread object for newly created thread.

Script

The AutoHotkey script to execute as string or variable containing a string. If you want to start a script from file simply use #Include directive. If you want to start empty script use #Persistent.

Parameters (optional)

Command line parameters that will be available in built-in variable A_Args object.

Title (optional)

Title to use for new script.

Wait (optional)

Milliseconds to wait for new script to start.

Library (optional)

The library handle returned by LoadLibrary or path of AutoHotkey.dll to create new thread in AutoHotkey.dll instead current library.
This parameter must be also used when creating a new thread in main process (AutoHotkey.exe) from AutoHotkey.dll.

General Remarks

To return the script in a thread you can use A_LineFile.

Methods
ahkFunction Call a function via SendMessage method.
ahkPostFunction Call a function via PostMessage method (does not wait until function returns).
ahkExecuteLine Executes script from given line pointer.
ahkLabel Goto (PostMessage) or Gosub (SendMessage) a Label.
ahkFindFunc Find a function and return its pointer.
ahkFindLabel Find a label and return its pointer.
addScript Add and optionally execute additional script/code from text/memory/variable.
ahkExec Execute some script/code from text/memory/variable temporarily.
ahkassign Assign a value to variable or pointer of variable.
ahkgetvar Retrieve a value from a variable.
ahkPause Pause Script.
ahkTerminate Exit Script.

Related

NewThread, ThreadObj

Examples

MyThread:=NewThread("Msgbox variable:=`"Thread`"")
While !Mythread.ahkReady()
  Sleep 100
MsgBox MyThread.ahkgetvar.variable