how to use the function of the main thread in thread1

Ask for help, how to use AHK_H, etc.
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

how to use the function of the main thread in thread1

08 Oct 2017, 19:21

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
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: how to use the function of the main thread in thread1

09 Oct 2017, 14:34

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
}
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

Re: how to use the function of the main thread in thread1

09 Oct 2017, 18:57

thx. it works well in ahk_h v2.
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

Re: how to use the function of the main thread in thread1

09 Oct 2017, 20:34

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
}



HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: how to use the function of the main thread in thread1

10 Oct 2017, 01:19

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
}
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

Re: how to use the function of the main thread in thread1

10 Oct 2017, 03:47

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)
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: how to use the function of the main thread in thread1

10 Oct 2017, 14:57

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!

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 29 guests