Please feel free to provide feedback or file bugs here.

ISE hangs after using a Windows Forms dialog

Votes from Connect: 12

Original Date Submitted: 4/4/2015 8:50:49 AM

Description:
********Contact Information********
Handle: Arnoud Jansveld
Site Name: PowerShell
Feedback ID: 1224213
***************************************

Frequency: PowerShell ISE
Regression: function Show-Form
{
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms") >$null
$form = New-Object System.Windows.Forms.Form
$label = New-Object System.Windows.Forms.Label
$label.Text = "Please close this form"
$label.AutoSize = $true
$form.Controls.Add($label)
$form.ShowDialog()
}

$result = Show-Form

# Workaround (slow):
# $result = Start-Job ${function:Show-Form} | Receive-Job -Wait -AutoRemoveJob

"Form result: " + $result.ToString()

Write-Warning "The following step may hang PowerShell ISE, save your work!"
Read-Host -Prompt "Hit Enter or Ctrl-C to abort"

# This generates a WM_SETTINGCHANGE broadcast message
[Environment]::SetEnvironmentVariable("foo", "bar", "User")

Problem Description:
After using ShowDialog() to display a Windows Forms dialog, the ISE will hang when it receives a WM_SETTINGCHANGE broadcast message (e.g. when changing display resolution, switching from a laptop screen to an external monitor or connecting to the current session from another machine via RDP).

This was reproduced on PowerShell ISE version 4 and 5 (Feb preview). Sadly it affects many useful scripts, including Lee Holmes' (awesome) Show-Object.

Product Studio item created by Connect Synchronizer due to creation of feedback ID 1224213 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=1224213).

Repro Steps:
function Show-Form
{
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms") >$null
$form = New-Object System.Windows.Forms.Form
$label = New-Object System.Windows.Forms.Label
$label.Text = "Please close this form"
$label.AutoSize = $true
$form.Controls.Add($label)
$form.ShowDialog()
}

$result = Show-Form

# Workaround (slow):
# $result = Start-Job ${function:Show-Form} | Receive-Job -Wait -AutoRemoveJob

"Form result: " + $result.ToString()

Write-Warning "The following step may hang PowerShell ISE, save your work!"
Read-Host -Prompt "Hit Enter or Ctrl-C to abort"

# This generates a WM_SETTINGCHANGE broadcast message
[Environment]::SetEnvironmentVariable("foo", "bar", "User")

Expected Results:
The script should show an empty dialog; after closing it and hitting Enter at the prompt the ISE should remain responsive (on some occasions the script has to be run more than once for the problem to occur).

This works fine in the regular PowerShell console.

Internal BugId: 14363

28 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    AdminJoey Aiello [MSFT] (Program Manager, Windows Server) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    4 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Bill E commented  ·   ·  Flag as inappropriate

        I have been having issues with ISE hanging on the display of forms for years. I have tried simple forms on each production ready version of ISE since Windows 7 was released and I have constantly seen the hang issue.
        I have tried the latest ISE Preview (Version 5.1.1) but still have no luck getting around the occasional hangs. I hope the ISE engineers can resolve this problem soon.

      • Anonymous commented  ·   ·  Flag as inappropriate

        This bug is very annoying for me beacuse I have a lot of script wih GUI forms.
        Is there any plan to fix this?

      • Mark commented  ·   ·  Flag as inappropriate

        I exhibit the same behavior and would really appreciate a fix to this. Running any of my scripts with a ShowDialog() means that I MUST close my ISE or else it will become unresponsive after a period of time.

      Feedback and Knowledge Base