Page 1 of 1
how to use the function of the main thread in thread1
Posted: 08 Oct 2017, 19:21
by xuezhe
Code: Select all
thread:=AhkThread("
(
sleep 5000
test:= var*3
MsgBox test
test(var)
)")
thread.ahkassign("var","2")
While(thread.ahkgetvar("test") =="")
{
Sleep 1000
}
MsgBox thread.ahkgetvar("test")
test(var)
{
Return 1
}
error
noexistent function
Re: how to use the function of the main thread in thread1
Posted: 09 Oct 2017, 14:34
by HotKeyIt
in ahk_h v1 you will need
exe.ahkFunction(""test"",var """")Code: Select all
thread:=AhkThread("
(
sleep 5000
test:= var*3
MsgBox test
exe:=AhkExported()
exe.ahkFunction("test",var "")
)")
thread.ahkassign("var","2")
While(thread.ahkgetvar("test") =="")
{
Sleep 1000
}
MsgBox thread.ahkgetvar("test")
test(var)
{
Return 1
}
Re: how to use the function of the main thread in thread1
Posted: 09 Oct 2017, 18:57
by xuezhe
thx. it works well in ahk_h v2.
Re: how to use the function of the main thread in thread1
Posted: 09 Oct 2017, 20:34
by xuezhe
HotKeyIt wrote:in ahk_h v1 you will need
exe.ahkFunction(""test"",var """")Code: Select all
thread:=AhkThread("
(
sleep 5000
test:= var*3
MsgBox test
exe:=AhkExported()
exe.ahkFunction("test",var "")
)")
thread.ahkassign("var","2")
While(thread.ahkgetvar("test") =="")
{
Sleep 1000
}
MsgBox thread.ahkgetvar("test")
test(var)
{
Return 1
}
ahk_h v2
return null ?
Code: Select all
thread:=AhkThread("
(
Sleep 500
exe:=AhkExported()
exe.ahkFunction("test",var,var1)
MsgBox exe.ahkgetvar("var1") ;retun null
)")
thread.ahkassign("var","2")
Sleep 3000
test(var,ByRef var1)
{
MsgBox var
var1:=var*3
MsgBox var1
Return 1
}
Re: how to use the function of the main thread in thread1
Posted: 10 Oct 2017, 01:19
by HotKeyIt
Yes, main exe has no variable var1:
Code: Select all
var1:="this is a test"
thread:=AhkThread("
(
Sleep 500
exe:=AhkExported()
exe.ahkFunction("test",var,var1)
MsgBox exe.ahkgetvar("var1") ;retun null
)")
thread.ahkassign("var","2")
While thread.ahkReady()
Sleep 100
test(var,ByRef var1)
{
MsgBox var
var1:=var*3
MsgBox var1
Return 1
}
Re: how to use the function of the main thread in thread1
Posted: 10 Oct 2017, 03:47
by xuezhe
HotKeyIt wrote:Yes, main exe has no variable var1:
Code: Select all
var1:="this is a test"
thread:=AhkThread("
(
Sleep 500
exe:=AhkExported()
exe.ahkFunction("test",var,var1)
MsgBox exe.ahkgetvar("var1") ;retun null
)")
thread.ahkassign("var","2")
While thread.ahkReady()
Sleep 100
test(var,ByRef var1)
{
MsgBox var
var1:=var*3
MsgBox var1
Return 1
}
thx,but I want to get the another value of var from the main thread function (not the returned value)
Re: how to use the function of the main thread in thread1
Posted: 10 Oct 2017, 14:57
by HotKeyIt
Function is local, you can only get global variables.
Also by the time you try to get the variable, function already exited and variables were cleared!
Re: how to use the function of the main thread in thread1
Posted: 10 Oct 2017, 22:18
by xuezhe
thx.