how to use the function of the main thread in thread1

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: how to use the function of the main thread in thread1

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

by HotKeyIt » 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!

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

by xuezhe » 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)

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

by HotKeyIt » 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
}

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

by xuezhe » 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
}



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

by xuezhe » 09 Oct 2017, 18:57

thx. it works well in ahk_h v2.

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

by HotKeyIt » 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
}

how to use the function of the main thread in thread1

by xuezhe » 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

Top