There was a problem with Sleep which is now fixed, update
AutoHotkey_H and following example will work, thanks for reporting btw.
When you assign
gui := in your thread, you replace the object you shared to dll so this will not work, instead use Alias in your main thread.
Also your thread needs to use
SetBatchLines, -1 otherwise the call will not return as it will do internal MsgSleep forever.
Code: Select all
thread := AhkThread("#Include <class_UI>`nSetBatchLines,-1`ngui := new UI( ""-DPIScale"", ""test"" )`ngui.Show( ""x10 y10 w500 h500"" )`nready:=1`nreturn" )
While !thread.ahkgetvar("ready")
Sleep 100
Sleep 500
Alias(gui,thread.ahkgetvar("gui",1))
gui.Hide()
MsgBox End
If you want your object to be CriticalObject (thread-safe), pass object pointer of gui to CriticalObject() in main thread:
Code: Select all
thread := AhkThread("#Include <class_UI>`nSetBatchLines,-1`ngui := CriticalObject(new UI( ""-DPIScale"", ""test"" ))`ngui.Show( ""x10 y10 w500 h500"" )`nguiptr:=&gui`nreturn" )
While !thread.ahkgetvar("guiptr")
Sleep 100
Sleep 500
gui:=CriticalObject(thread.ahkgetvar("guiptr")+0)
gui.Hide()
MsgBox End
ExitApp