PowerShell crash when calling ShowDialog for the second time. This error occurred when leaving PowerShell console for a long time(10-20 minutes)
#Load WPF assembly for Powershell.exe
Add-Type -AssemblyName PresentationFramework
#Create WPF Window object
$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
</Grid>
</Window>
"@
#First call(Need to close window manually)
$window = [Windows.Markup.XamlReader]::Parse($xaml)
$window.Topmost = $True
$window.ShowDialog()
#Wait 20 minutes
sleep (60 * 20)
#Second call
$window = [Windows.Markup.XamlReader]::Parse($xaml)
$window.Topmost = $True
$window.ShowDialog() #cause Win32Exception
$async = $window.Dispatcher.InvokeAsync({
$window.ShowDialog() | Out-Null
})
$async.Wait() | Out-Null