make 2nd thread to exit mainscript Topic is solved

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

make 2nd thread to exit mainscript

Post by ananthuthilakan » 17 Nov 2022, 03:14

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
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

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

Post by murataygun » 17 Nov 2022, 06:33

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
Post Reply

Return to “AutoHotkey_H”