Powershell Throttle Multi thread jobs via job completion

后端 未结 6 1495
情歌与酒
情歌与酒 2020-12-07 03:23

All the tuts I have found use a pre defined sleep time to throttle jobs. I need the throttle to wait until a job is completed before starting a new one. Only 4 jobs can be r

6条回答
  •  时光取名叫无心
    2020-12-07 04:17

    I noticed that every Start-Job command resulted in an additional conhost.exe process in the task manager. Knowing this, I was able to throttle using the following logic, where 5 is my desired number of concurrent threads (so I use 4 in my -gt statement since I am looking for a count greater than):

    while((Get-Process conhost -ErrorAction SilentlyContinue).Count -gt 4){Start-Sleep -Seconds 1}
    

提交回复
热议问题