PowerShell ISE often gets frozen


For starters, I've written a very simple test PowerShell script:

Import-Module -Name C:\UIAutomation.0.8.5.NET40\UIAutomation.dll -Verbose

# imput parameters: target process name and Title
$tgProcessName = "NotePad++"

select the window

$tgWnd = Get-UIAWindow -ProcessName $tgProcessName
Save-UIAScreenshot -InputObject $tgWnd -Description $tgProcessName

And I run this by hitting F5 within the PowerShell [3.0, running on Windows 7] ISE.

The best I get from this is a leftover "red outline" that stays around the captured window even if the application is closed, until I terminate the ISE (an hourglass is displayed when the mouse is hovered over that outline). In this "best" case control does get returned to the ISE. (see screenshots)

The worst case, that happens quite often, is that control is never returned to the ISE. I have to terminate the powershell_ise.exe process.

Is this a known issue?

What am I doing wrong?

file attachments


apetrovskiy wrote Nov 21, 2013 at 1:33 PM

I could not say much about working in ISE as I write code mostly in SharpDevelop 4.3 (there's no intellisense, but excellent search and navigation across the number of files).
I tried the current version (pre-alpha of 0.8.7 what is practically the same as the last beta of 0.8.6 (I heartily recommend you use the last version available).
The combination of ISE (3.0 on Windows 8 x64 I"m sitting on now) and the latest version of UIA works well.

The 'frozen IDE' issue I saw the last time with PowerGUI 3.5 or 3.6 running from a flash disk. I think it was IDE's internal problem.

Regarding the red rectangle, as well as pink and blue ones (and rectangles in the Show Execution mode) that are seen in certain situations, I was asked to turn them down after several seconds. Rectangles, of course, are unaware of what they round. Currently, I postponed auto-hiding of rectangles as I'm working on deep refactoring of UIA.

sba wrote Nov 21, 2013 at 2:33 PM


ISE is a very useful environment for PS development, and I cannot imagine coding in any language that supports introspection (a.k.a. reflection) without IntelliSense or a similar mechanism in the IDE.

For now, I'll check whether adding:

[UIAutomation.Preferences]::Highlight = $false

makes the freezes disappear...

apetrovskiy wrote Nov 21, 2013 at 4:37 PM

There is a special cmdlet: Hide-UIACurrentHighlighter

The Highlight setting works for the line of code next to the current pipeline (i.e., cmdlets in pipeline work as a bunch, and the new value of this variable would be probably available after the next line of code starts running. This is not a problem, usually, except for the case you ran a line of code from command line, thinking about the next line and watching the last red rectangle).

If the term 'frozen' was about the rectangle, this is not a problem as it seems to me. PowerGUI from a flash disk froze a couple of times to death, THIS is 'frozen' :)

If you have an idea how to switch the rectangle off wisely (i.e., after some (which?) time or after an event, etc), feel free to discuss. Timer is not a good solution as it is needed in manual execution and will definitely a surprise in scripts (imagine, after several seconds, highlighter suddenly turns off).
The most frequent usage of the highlighter is manual or automatic saving of screenshots with a rectangle around the last successfully captured AutomationElement.

Regarding IDE, I'm working now on a monitoring product and generate actions via Exchange, Active Directory, SharePoint, etc cmdlets. I write a piece of code in powershell.exe, make it working, copy it from the console to a notepad or directly to SharpDevelop and generalize it there (i.e., change names to variables and functions). Excellent search/replace across tens of files makes me more happy than all other PowerShell IDEs features.

sba wrote Nov 22, 2013 at 8:24 AM

What I meant by "frozen" is that the PowerShell ISE doesn't respond to commands anymore, it doesn't redraw its UI anymore. The only way to regain control is to kill the process (e.g. using "pskill powershell_ise").

Given the name (with "hide" in it) I would think that Hide-UIACurrentHighlighter does just that: hide the highlighter, which IMO is not the same as disabling it (assuming that's what "[UIAutomation.Preferences]::Highlight = $false" does).

How would you explain that this lockup doesn't always occur?

apetrovskiy wrote Nov 22, 2013 at 10:40 AM

Yes, settings [UIAutomation.Preferences]::Highlight, [UIAutomation.Preferences]::HighlightParent and [UIAutomation.Preferences]::HighlightCheckedControl turn off highlighter completely (the previous request from a user of the framework was about turning it off after an element was highlighted, so that I thought you wanted the same).

I tried my current version (pre-0.8.7 that is approximately 0.8.6 Beta 5+) on ISE 3.0 on Windows 8 x64 Ent and on Windows 7 x64 Ent (both versions: for .NET 3.5 and .NET 4.0), and found no problems with the highlighter. 0.8.6 Beta 4 also works as expected. I suspect that yur problem could stem from your environment. Could it be that your ISE is running not in STA mode?

I uploaded the first alpha of 0.8.7 - could you try this in your ISE with the highlighter on?

softy wrote May 14, 2014 at 2:09 PM

win2008 sp2 +ps ise 3.0 +uiautomation 0.8.7 beta2 often gets frozen


softy wrote May 14, 2014 at 2:15 PM

UIAutomation.Preferences::HighlightCheckedControl =$false

softy wrote May 14, 2014 at 2:20 PM

[UIAutomation.Preferences]::HighlightCheckedControl =$false

apetrovskiy wrote May 14, 2014 at 3:57 PM

Unfortunately, there's no solution right now.

Some applications with PowerShell support often get frozen working with console thread and GUI thread simultaneously. I saw this on ISE and PowerGUI.
Probably, this is caused by debugging: you are watching a value of variable and IDE gets its value from console and puts in in the GUI (tooltip).

I can enulate this in powershell.exe too: via a static method of UIAutomation it's possible to create an AutomationElement in the console thread what is critical to powershell.exe (as I understand the problem).

Looking at your code, I can recommend you cut out the part with UiAutomation and put it in another function (the 'Extract method' refactoring). This allows you to walk part with UIAutomation with Step Over (F10), not debugging this part. It' usually nothing to debug in UiAutomation: a control exists or doesn't, what to debug here?