There are no crashes when assigning the thread script to a variable or reading into a variable from a file
Tested with the below versions (32-Bit, 64-bit and MT Versions), and the results are same
H1 1.1.32.0
H1 1.1.33.2
This simple test failed
ThreadScript.ahk
Code: Select all
#NoEnv
#NoTrayIcon
MsgBox, % "In Thread`nParameter 1: " A_Args.1 "`nParameter2" A_Args.2 ;All good so far
MsgBox, Thread done its job! ;All good so far
ExitApp ;Crashing at this stage
MainScript_Com_Method_Failed.ahk
Code: Select all
P1 := 111
P2 := 222
oThread := ComObjCreate("AutoHotkey.Script") ;Tested with 32-bit, 64-bit and MT-Versions
If IsObject(oThread) {
oThread.AhkTextDll("#Include <ThreadScript>",, P1 " " P2)
Sleep, 100
While (State := oThread.AhkReady()) {
ToolTip, % "Thread State: " State " (Iteration: " A_Index ")"
Sleep, 100
}
MsgBox, Main: Thread finished its job
} Else
MsgBox, Main: Error`nCom Object not found!
MsgBox, Main: Exits Here
ExitApp
Code: Select all
;oThread := AhkMini("#Include <ThreadScript>", P1 " " P2) ;same result
;oThread := AhkMini("#Include " A_ScriptDir "\Lib\ThreadScript.ahk", P1 " " P2) ;same result
oThread := AhkMini("#Include ThreadScript.ahk", P1 " " P2) ;same result
Sleep, 100
While (State := oThread.AhkReady()) {
ToolTip, % "Thread State: " State " (Iteration: " A_Index ")"
Sleep, 100
}
;oThread.AhkTerminate()
oThread := ""
MsgBox, Main: Thread finished its job
MsgBox, Main: Exits Here
ExitApp
Code: Select all
MainScript_Working.ahk
[code]
P1 := 111
P2 := 222
FileRead, ThreadScript, %A_ScriptDir%\Lib\ThreadScript.ahk
/* Or assigning it to a variable
ThreadScript =
(
#NoEnv
#NoTrayIcon
MsgBox, `% "In Thread``nParameter 1: " A_Args.1 "``nParameter2" A_Args.2
MsgBox, Thread done its job!
ExitApp
)
*/
GoTo, _Method1
;GoTo, _Method2
_Method1: ; Using Com Object
oThread := ComObjCreate("AutoHotkey.Script")
If IsObject(oThread) {
oThread.AhkTextDll(ThreadScript,, P1 " " P2)
Sleep, 100
While (State := oThread.AhkReady()) {
ToolTip, % "Thread State: " State " (Iteration: " A_Index ")"
Sleep, 100
}
ToolTip
MsgBox, Main: Thread finished its job
} Else
MsgBox, Main: Error`nCom Object not found!
MsgBox, Main: Exits Here
ExitApp
_Method2: ; Using AhkMini()
oThread := AhkMini(ThreadScript, P1 " " P2)
Sleep, 100
While (State := oThread.AhkReady()) {
ToolTip, % "Thread State: " State " (Iteration: " A_Index ")"
Sleep, 100
}
ToolTip
;oThread.AhkTerminate()
oThread := ""
MsgBox, Main: Thread finished its job
MsgBox, Main: Exits Here
ExitApp
Please Help!