labrint wrote: ↑26 Feb 2019, 04:48
I don't think you can run two functions at once in a single script because AHK does not support multithreading.
This statement is partially true.
AHK emulates multi-threading.
Only one "thread" can be active at one time, but when you use something like SetTimer, what happens is, when the timer fires, it interrupts the current thread, runs the timer code, then relinquishes control back to the interrupted thread.
So as long as your SetTimer function ends (hits a return statement), then you have, in effect, multi-threaded.
The code the OP posted already does this, he just does not realize it.
Code: Select all
#Persistent
SetTimer, Internet, 500
Loop {
Tooltip % "Other code running... " A_TickCount
Sleep 100
}
return
ConnectedToInternet(flag=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}
Internet:
If ConnectedToInternet()
{
SoundBeep, 1000, 100
}
else {
SoundBeep, 500, 100
}
return
Esc::Exitapp