I'm learning real multi-threading using AutoHotkey.dll. To get started, I'd like to know if this is possible.
This lists current existing processes and the associated command lines.
Gui, Process:Add, ListView, x2 y0 w400 h500, PID|Process Name|Command Line
Gui, Process: default
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
LV_Add("", process.ProcessID, process.Name, process.CommandLine)
Gui, Process:Show,, Process ListThis lists current existing windows and processes.WinGet, WindowList, List
Gui, Windows:Add, ListView, x2 y0 w600 h500, PID|Process Name|Window Handle|Window Title
Gui, Windows: default
loop % WindowList
{
WinGetTitle, WindowTitle , % "ahk_id " WindowList%A_Index%
WinGet, ProcessName , ProcessName, % "ahk_id " WindowList%A_Index%
WinGet, PID , PID, % "ahk_id " WindowList%A_Index%
LV_Add("", PID, ProcessName, WindowList%A_Index%, WindowTitle)
}
LV_ModifyCol()
Gui, Windows:Show,, Window ListEach one of them can retrieve different information associated with process ID so I'd like to run them simultaneously and combine them into one object.Thread A:
;oProc := {} ;assuming oProc is declared as an object already.
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process") {
if !IsObject(oProc[PID])
oProc[PID] := {}
oProc[PID] := {CommandLine : process.CommandLine
, Name : process.Name}
}
threadA := true
Thread B:
;oProc := {} ;assuming oProc is declared as an object already.
WinGet, WindowList, List
loop % WindowList
{
WinGetTitle, WindowTitle , % "ahk_id " WindowList%A_Index%
WinGet, PID , PID, % "ahk_id " WindowList%A_Index%
if !IsObject(oProc[PID])
oProc[PID] := {}
oProc[PID]["WindowTitle"] := WindowTitle
oProc[PID]["WindowHandle"] := WindowList%A_Index%
}
threadB := true
Main Thread:
While !threadA || !threadB
sleep 10
Gui, ProcAndWins: Add, ListView, x2 y0 w600 h500, PID|Process Name|Command Line|Window Handle|Window Title
Gui, ProcAndWins: default
For pid, oPid in oProc
LV_Add("", pid, oPid.Name, oPid.CommandLine, oPid.WindowHandle, oPid.WindowTitle)
LV_ModifyCol()
Gui, ProcAndWins:Show,, Process and Window ListCould somebody provide a working example for this? Thanks for your help.




