Háttérben futtatás Foreach-Object-el

A PowerShell 7.0-ban megjelent Foreach-Object -Parallel háttérben futásra is lehetőséget biztosít az -AsJob kapcsolóval:

PS C:\> 1..10 | ForEach-Object -Parallel {Start-Sleep $_; $_} -AsJob

 

Id     Name            PSJobTypeName   State         HasMoreData     Location

--     ----            -------------   -----         -----------     --------

12     Job12           PSTaskJob       Running       False           PowerShell

Látható, hogy itt valójában egy Job-ot kaptunk, azonban ez tartalmazza a ténylegesen munkát végző gyerek folyamatokat:

PS C:\> Get-Job -IncludeChildJob

 

Id     Name            PSJobTypeName   State         HasMoreData     Location

--     ----            -------------   -----         -----------     --------

12     Job12           PSTaskJob       Running       True            PowerShell

13     Job13           PSTaskChildJob  Completed     True            PowerShell

14     Job14           PSTaskChildJob  Completed     True            PowerShell

15     Job15           PSTaskChildJob  Completed     True            PowerShell

16     Job16           PSTaskChildJob  Completed     True            PowerShell

17     Job17           PSTaskChildJob  Completed     True            PowerShell

18     Job18           PSTaskChildJob  Completed     True            PowerShell

19     Job19           PSTaskChildJob  Running       False           PowerShell

20     Job20           PSTaskChildJob  Running       False           PowerShell

21     Job21           PSTaskChildJob  Running       False           PowerShell

22     Job22           PSTaskChildJob  Running       False           PowerShell

Az eredményekhez a szokásos módon, a Receive-Job-bal jutunk:

PS C:\> Get-Job | Receive-Job

1

2

3

4

5

6

7

8

9

10



Word To HTML Converter