Skip to content

Start-ThreadJob -StreamingHost $Host leaves behind progress bars #24575

@alx9r

Description

@alx9r

Prerequisites

Steps to reproduce

I appreciate the progress bar improvements since the PowerShell 5 era. #14414's small progress bars I think especially improve the experience.

The code below starts 100 jobs each of which takes about a second to complete. Each job has a progress updated at 10 millisecond intervals. After the jobs complete, the script sleeps for 1000 seconds. At first the progress bars seem to complete as expected. When the jobs complete, however, a number of progress bars with differing completion percentages reappear and remain indefinitely.

Note that reducing the value of -Milliseconds seems to increase the number of progress bars that reappear.

I see #3366 mentions some progress bar limitations but that issue predates #14414, and I'm not sure which still apply. This all leads me to the following questions:

  1. Is the repro here expected, as intended, or as designed?
  2. Is there a workaround to get the progress bars to clear reliably?

.\repro.ps1

$jobs =
$(foreach ($iteration in 1..100) {
        Start-ThreadJob `
            -StreamingHost $Host `
            -ArgumentList  $iteration `
            -ScriptBlock  {
                param($iteration)
                $id = Get-Random ([int]::MaxValue) -Minimum 0
                1..100 |
                    % {
                        Write-Progress -Activity "Job $iteration Activity $_" -Id $id -PercentComplete $_
                        Start-Sleep -Milliseconds 10
                    }
                Write-Progress -Id $id -Completed
        }
})

$jobs | Wait-Job | Receive-Job -Keep
Start-Sleep -Seconds 1000

Expected behavior

PS> .\repro.ps1
jobs complete

Actual behavior

PS> .\repro.ps1
jobs complete
Job 4 Activity 100 [Processing    ...]
Job 3 Activity 100 [Processing    ...]
Job 5 Activity 99 [Processing     ...]
Job 7 Activity 100 [Processing    ...]
Job 8 Activity 100 [Processing    ...]
Job 15 Activity 99 [Processing    ...]
Job 13 Activity 100 [Processing   ...]
Job 14 Activity 99 [Processing    ...]
Job 12 Activity 100 [Processing   ...]
Job 17 Activity 100 [Processing   ...]
Job 24 Activity 99 [Processing    ...]
Job 39 Activity 100 [Processing   ...]
Job 43 Activity 100 [Processing   ...]
Job 44 Activity 99 [Processing    ...]
Job 49 Activity 100 [Processing   ...]
Job 48 Activity 100 [Processing   ...]
Job 55 Activity 100 [Processing   ...]
Job 57 Activity 100 [Processing   ...]
Job 64 Activity 98 [Processing    ...]
Job 63 Activity 99 [Processing    ...]
Job 68 Activity 100 [Processing   ...]
Job 70 Activity 99 [Processing    ...]
Job 69 Activity 99 [Processing    ...]
Job 72 Activity 100 [Processing   ...]
Job 75 Activity 100 [Processing   ...]
Job 78 Activity 100 [Processing   ...]
Job 77 Activity 100 [Processing   ...]
Job 82 Activity 100 [Processing   ...]
Job 83 Activity 100 [Processing   ...]
Job 84 Activity 100 [Processing   ...]
Job 88 Activity 100 [Processing   ...]
Job 87 Activity 100 [Processing   ...]
Job 90 Activity 99 [Processing    ...]
Job 89 Activity 99 [Processing    ...]
Job 94 Activity 100 [Processing   ...]
Job 93 Activity 100 [Processing   ...]
Job 100 Activity 100 [Processing  ...]
Job 98 Activity 99 [Processing    ...]
Job 99 Activity 99 [Processing    ...]

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working Group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions