Hi,
I would like a continuously looping progress bar for the duration of my code. I’m having some success in getting a job to loop until the condition is met. I understand that you need to use Receive-Job to get the jobs output though, but this requires me to use -Wait, which stops it getting to the point where the condition changes value, causing the progress to never stop:
[pre]
$completed = $false
$i = 0
Start-Job -ScriptBlock {
Do {
$i++
Write-Progress -Activity “Test” -PercentComplete $i
if ($i -eq 100) {
$i = 0
}
} While ($completed -ne $true)
}
Start-Sleep -Seconds 5
$completed = $true
Get-Job | ForEach {
Stop-Job -Id $.Id
Remove-Job -Id $.Id
}
[/pre]
I’ve also had a play with Workflows with Parallel but because of the variable scoping issue I gave up:
[pre]
Workflow Test {
$completed = $false
Parallel {
Sequence {
Start-Sleep -Seconds 5
$Workflow:completed = $true
}
Do {
$i++
Write-Progress -Activity “Progress Test” -PercentComplete $i
Write-Output “completed: $Workflow:completed”
if ($i -eq 100) {
$i = 0
}
} While ($Workflow:completed -ne $true)
}
}
Test
[/pre]
Any suggestions?
Thanks