ok so I added some logging code into the script and tested heres what I get:
Script with logging
Code: Select all
global processes := {}
global dbgLogger := new LogFile(,false,,"mm.ss")
LogonUI_Func := Func("ProcessStatusUpdate").Bind("LogonUI")
LockAppHost_Func := Func("ProcessStatusUpdate").Bind("LockAppHost")
LockApp_Func := Func("ProcessStatusUpdate").Bind("LockApp")
SetTimer, %LogonUI_Func%, -1
SetTimer, %LockAppHost_Func%, -1
SetTimer, %LockApp_Func%, -1
While(!IsScreenLocked()) {
Sleep, 2000
}
MsgBox, % "Screen Got Locked"
ExitApp, 0
return
ProcessStatusUpdate(exename) {
dbgLogger.AddEntry(A_TickCount . ": " . "timer initiate function for " . exename)
processes[exename] := false
Loop {
Process, Wait, % exename . ".exe"
processes[exename] := (ErrorLevel ? true : false)
dbgLogger.AddEntry(A_TickCount . ": " . exename . " was found=" . processes[exename])
Process, WaitClose, % exename . ".exe"
processes[exename] := (ErrorLevel ? true : false)
dbgLogger.AddEntry(A_TickCount . ": " . exename . " was found=" . processes[exename])
Sleep, 25
}
}
IsScreenLocked() {
dbgLogger.AddEntry(A_TickCount . ": " . "Screen lock check: LogonUI=" . processes["LogonUI"] . ", LockAppHost=" . processes["LockAppHost"] . ", LockApp=" . processes["LockApp"])
return (processes["LogonUI"] and processes["LockAppHost"] and processes["LockApp"])
}
;;-----------------------------
Class LogFile {
__New(filename := "", insertAtTop := true, maxEntries := 150, dt_format := "-1") {
A_ScriptNameNoExt := RegExReplace(A_ScriptName, "iDU)^(.*)\.(ahk|exe)$", "$1") ;not usually here
this.timestamp_enabled := (dt_format != "-1" ? true : false)
this.timestamp_format := dt_format
this.filename := AbsolutePath(filename ? filename : A_ScriptDir . "\" . A_ScriptNameNoExt . ".log")
this.max := maxEntries
this.insertAtTop := insertAtTop
this.Slurp()
this.Prune()
this.UpdateFile()
}
AddEntry(message) {
message := "[" . A_ScriptNameNoExt . "]" . message
if(this.timestamp_enabled)
message := RTrim("[" . FormatTime(A_Now, this.timestamp_format) . "] " . message, "`r`n")
split_msg := StrSplit(message, "`n")
Loop % split_msg.Length() {
if(this.insertAtTop) {
this.contents.InsertAt(A_Index, split_msg[A_Index])
} else {
this.contents.Push(message)
}
}
this.Prune()
this.UpdateFile()
}
UpdateFile() {
hFile := FileOpen(this.filename, "w-rwd")
for i, v in this.contents {
hFile.WriteLine(v)
}
hFile.Close()
}
Prune() {
While(this.max < this.contents.Length()) {
if(this.insertAtTop)
this.contents.Pop()
else
this.contents.RemoveAt(1)
}
}
Slurp() {
this.contents := Array()
Loop, Read, % this.filename
{
this.contents.Push(A_LoopReadLine)
}
}
__Delete() {
this.timestamp_enabled := ""
this.timestamp_format := ""
this.filename := ""
this.max := ""
this.insertAtTop := ""
While(this.contents.Length() > 0)
this.contents.Pop()
}
}
AbsolutePath(filename) {
if(filename ~= "S)^\..+$") {
filename := A_WorkingDir . SubStr(filename, 2)
}
Loop {
filename := RegExReplace(filename, "S)^(.+\\)?.+[^\.]{2}\.\.[\\]?(.+)?$", "$1$2", replaces)
} Until !replaces
return filename
}
FormatTime(YYYYMMDDHHMISS := "", Format := "") {
FormatTime, output_var, %YYYYMMDDHHMISS%, %Format%
return output_var
}
Logfile
Code: Select all
[44.45] []3742578: Screen lock check: LogonUI=, LockAppHost=, LockApp=
[44.46] []3742687: timer initiate function for LogonUI
[44.46] []3742796: timer initiate function for LockApp
[44.58] []3755500: LockApp was found=1
[45.11] []3768125: LockApp was found=0
;restarted script
[01.12] []4728656: Screen lock check: LogonUI=, LockAppHost=, LockApp=
[01.12] []4728765: timer initiate function for LogonUI
[01.12] []4728781: timer initiate function for LockAppHost
[01.12] []4728796: timer initiate function for LockApp
[01.35] []4752375: LockApp was found=1
[01.55] []4772250: LockApp was found=0
I ran the script, waited a few seconds, locked the screen, waited a few seconds, unlocked waited. I ran it twice to be sure.
Seems SetTimer is successful [sometimes] but
process, wait never gets executed for any but the last SetTimer and the
While(!IsScreenLocked()) { loop only iterates once...
The log also shows that
ProcessStatusUpdate function works [atleast for LockApp] but just isn't being run from the other timers. I guess something like GreenThreads would come in handing for these sort of things instead of using Timers in an unintended way.;
still no idea why this is happening...