Last active
August 29, 2015 14:09
-
-
Save tmplinshi/084590ff3782b3b607d7 to your computer and use it in GitHub Desktop.
多进程
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class mProcess | |
{ | |
static pidList := [] | |
; 等待进程小于指定数量 | |
wait(MaxRun = 1) { | |
Loop { | |
count := 0 | |
newList := [] | |
For i, pid in this.pidList | |
{ | |
Process, Exist, %pid% | |
If ErrorLevel | |
count ++, newList.Insert(pid) | |
} | |
If (!count || count < MaxRun) | |
Break | |
Else | |
Sleep, 1000 | |
} | |
this.pidList := newList | |
} | |
addPID(pid) { | |
this.pidList.Insert(pid) | |
} | |
waitFinish() { | |
this.wait(1) | |
} | |
} | |
/* | |
Loop, 10 { | |
mProcess.wait(5) ; 等待进程小于 5 个 | |
Run, notepad,,, pid ; 运行 notepad.exe,获取 PID | |
mProcess.addPID(pid) ; 记录这个 PID | |
} | |
mProcess.waitFinish() ; 等待所有进程结束,也可以用 mProcess.wait(1) | |
MsgBox, finish! | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment