Page 1 of 1
How to share variables between main threads and others ?
Posted: 01 Jan 2024, 06:27
by LOVE HOTKEY
I am using thqby/AutoHotkey_H v2.1-alpha.8. I try to use dllcall funtion,but seems to not right.
Code: Select all
test1 := "test1"
newScripts :="
(
{
a::b
test2 := "test2"
}
)"
newT := NewThread(newScripts)
dllpath:=A_AhkDir "\AutoHotkey64.dll"
MsgBox DllCall(dllpath "\ahkGetVar","Str",test2,"Uint",newT)
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]
- image.png (145.12 KiB) Viewed 2286 times
- image.png (35 KiB) Viewed 2286 times
Re: How to share variables between main threads and others ?
Posted: 01 Jan 2024, 08:58
by thqby
Re: How to share variables between main threads and others ?
Posted: 01 Jan 2024, 12:03
by LOVE HOTKEY
@thqbyThank you so much!
But i still not figure out how to make them communicate correctly.
I found out if add this line "MsgBox Worker(A_MainThreadID)['myvar']", Msgbox dont work anymore.
Code: Select all
myvar := 50
Script := "
(
Persistent(true)
MsgBox Worker(A_MainThreadID)['myvar']
var := 1000
)"
t := Worker(Script)
MsgBox t["var"]
Alias(var := 0, ahkGetVar('var', 1, t.ThreadID))
MsgBox(var)
Could you please show me an example about how to make variables can write a read between Main and other Threads very frequently?
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
Re: How to share variables between main threads and others ?
Posted: 01 Jan 2024, 12:44
by boiler
@LOVE HOTKEY — Please use [code][/code] tags when posting code on the forum. Thank you.
Re: How to share variables between main threads and others ?
Posted: 15 Jan 2024, 06:52
by thqby
MsgBox Worker(A_MainThreadID)['myvar'] interrupted script execution, and var has not been assigned.