Page 1 of 1

make 2nd thread to exit mainscript

Posted: 17 Nov 2022, 03:14
by ananthuthilakan

Code: Select all

2ndthread =
( 
#Persistent
#NoTrayIcon
n:=5
loop,
  {
sleep, 500
n++
Tooltip, `% n
if (n > 10)
	ExitApp  
}
)

dllpath:=A_AhkDir "\AutoHotkey.dll"
DllCall("LoadLibrary","Str",dllpath) 
DllCall(dllpath "\ahktextdll","Str",2ndthread,"Str","","Str","","CDecl") 
While DllCall(dllpath "\ahkReady")
  Sleep 100 
dll:=AhkThread(2ndthread)
While dll.ahkReady()
  Sleep 100 ;
  
 
T:: 
MsgBox, mainscript ; when n from 2ndthread becomes greater than 10 i want this main script to show a messagebox and Exit the entire app.
return
i am new to multithreading

what i am trying to do
----------------------------------------------------
when n from 2ndthread becomes greater than 10 i want this main script to show a messagebox and Exit the entire app.

current behaviour
---------------------------------------------------
it only exit the 2ndthread

Hope anybody will give me some insights into it

Re: make 2nd thread to exit mainscript  Topic is solved

Posted: 17 Nov 2022, 06:33
by murataygun

Code: Select all

2ndthread =
( 
#Persistent
#NoTrayIcon

AhkExe := AhkExported()
n:=5
loop,
  {
sleep, 500
n++
Tooltip, `% n
if (n > 10)
	AhkExe.ahkFunction["ExitFunction"]
}
)

dllpath:=A_AhkDir "\AutoHotkey.dll"
DllCall("LoadLibrary","Str",dllpath) 
DllCall(dllpath "\ahktextdll","Str",2ndthread,"Str","","Str","","CDecl") 
While DllCall(dllpath "\ahkReady")
  Sleep 100 
dll:=AhkThread(2ndthread)
While dll.ahkReady()
  Sleep 100 ;
  
 
ExitFunction() {
Msgbox, Variable n reached to value 10.
ExitApp   ;Both thread and the main script will exit.
}
T:: 
MsgBox, mainscript ; when n from 2ndthread becomes greater than 10 i want this main script to show a messagebox and Exit the entire app.
return