Product: PowerShell Universal
Version: 5.3.2
I have a rather expensive operation that I’m calling to load information from various sources for a provided entity. I have a large collection of entities that will need to be loaded at the same time. In another space, I would typically move forward with async rendering, although I can’t seem to get the rendering process working.
Consider the following method that works for synchronous rendering:
New-UDDynamic -Id "asyncContainer" -Content {
# New-EntityDisplay gathers and formats data for a provided entity,
# then displays it according to our structure.
foreach ($e in $Entities) {
New-EntityDisplay -Entity $e
}
}
This is heavily trimmed down to provide just the process; there are additional operations happening as well. Now, the PowerShell asynchronous model would have me do something similar to:
New-UDDynamic -Id "asyncContainer" -Content {
$EntityJobs = [System.Collections.Generic.List[psobject]]::new()
foreach ($e in $Entities) {
$EntityCreationJob = Start-ThreadJob -InputObject { id = $e.id; } -ScriptBlock {
New-EntityDisplay -Entity $input.id
}
$EntityJobs.Add($EntityCreationJob)
}
# This is where the app would wait for each job to finish, then receive and render:
Receive-Job [Array]$EntityJobs -Wait
}
However, the jobs never seem to be received. Has anyone had success with attacking such a problem?