Skip to content

Test-Connection hangs when used in a Windows form #12021

@ghost

Description

Steps to reproduce

Create a simple Windows form that utilizes the "Test-Connection" cmdlet. In practice the form is more complex - but the example below provides a simple test to reproduce the issue and eliminate extra complexity.

Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Sample Form"
$Button = New-Object Windows.Forms.Button
$Button.Text = "Test"
$Button.Location = New-Object Drawing.Point(100,100)
$Button.Add_Click({
    $Button.Text = "Running..."
    $Button.Enabled = $false
    Test-Connection $env:COMPUTERNAME -Count 3 -Quiet
    $Button.Text = "Test"
    $Button.Enabled = $true
})
$Form.Controls.Add($button)
$Form.ShowDialog()

Expected behavior

Test-Connection should complete and continue on with the script. This cmdlet works correctly when running from command line or non-form based script. When called from a Windows form, the Test-Connection just hangs the script/form indefinitely. I have tried various combinations of parameters such as removing "-quiet" and "-count". Maybe this is not a bug, and I am just overlooking some parameter or alternate method to call this cmdlet.

Actual behavior

Form hangs; you have to kill the Pwsh.exe process.

Environment data

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-DuplicateThe issue is a duplicate.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions