winforms – 使用Windows窗体锁定脚本终止后的PowerShell ISE分
发布时间:2020-12-13 20:22:35 所属栏目:Windows 来源:网络整理
导读:我在这里有一个有趣的问题.我创建一个日历选择器,供我们创建帐户时使用.它工作正常,并且仍在进行中,但是我注意到,当我在PowerShell ISE中运行脚本时,几分钟后它会锁定(我可以在之前几分钟编辑和保存代码).事件日志中没有任何内容.我得到一个对话框,说PowerSh
我在这里有一个有趣的问题.我创建一个日历选择器,供我们创建帐户时使用.它工作正常,并且仍在进行中,但是我注意到,当我在PowerShell ISE中运行脚本时,几分钟后它会锁定(我可以在之前几分钟编辑和保存代码).事件日志中没有任何内容.我得到一个对话框,说PowerShell是无响应的.内存使用情况似乎也正常.我不知道发生了什么.
无论我如何运行Powershell ISE(以管理员身份运行,运行另一个帐户和正常的ISE),我都在运行Windows 8.1. 一个同事建议它可能是公寓模型,所以我尝试过STA和MTA,但是问题出现在两种情况之中.当从控制台主机运行相同的代码时,不会发生这种情况. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $objForm = New-Object Windows.Forms.Form $objForm.Text = "Select a Date" $objForm.Size = New-Object Drawing.Size @(490,250) $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True $objForm.Add_KeyDown({ if ($_.KeyCode -eq "Enter") { $script:dtmDate=$objCalendar.SelectionStart $objForm.Close() } }) $objForm.Add_KeyDown({ if ($_.KeyCode -eq "Escape") { $objForm.Close() } }) $objCalendar = New-Object System.Windows.Forms.MonthCalendar $objCalendar.Text = "Start" $objCalendar.ShowTodayCircle = $False $objCalendar.MaxSelectionCount = 1 $objForm.Controls.Add($objCalendar) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog() if ($dtmDate) { Write-Host "Date selected: $dtmDate" } $objForm.Dispose() 在回应@独特的保罗·史密斯 function Find-CalenderDateTest { [CmdletBinding()] param( [Parameter( Mandatory=$false )] [ValidateSet('long','short','powerpoint')] [ValidateNotNullOrEmpty()] [string] $DateFormat ) Begin{ [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $objForm = New-Object Windows.Forms.Form $objForm.Text = "Select a Date" $objForm.Size = New-Object Drawing.Size @(243,250) $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True $dtmDate = $null $objForm.Add_KeyDown( { if ($_.KeyCode -eq "Enter") { $dtmDate=$objCalendar.SelectionStart $objForm.Close() } }) $objForm.Add_KeyDown({ if ($_.KeyCode -eq "Escape") { $objForm.Close() } }) #region OK Button $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(20,175) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = "OK" # Got rid of the Click event for OK Button,and instead just assigned its DialogResult property to OK. $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $objForm.Controls.Add($OKButton) # Setting the form's AcceptButton property causes it to automatically intercept the Enter keystroke and # treat it as clicking the OK button (without having to write your own KeyDown events). $objForm.AcceptButton = $OKButton #endregion #region Cancel Button $CancelButton = New-Object System.Windows.Forms.Button $CancelButton.Location = New-Object System.Drawing.Size(80,175) $CancelButton.Size = New-Object System.Drawing.Size(75,23) $CancelButton.Text = "Cancel" # Got rid of the Click event for Cancel Button,and instead just assigned its DialogResult property to Cancel. $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $objForm.Controls.Add($CancelButton) # Setting the form's CancelButton property causes it to automatically intercept the Escape keystroke and # treat it as clicking the OK button (without having to write your own KeyDown events). $objForm.CancelButton = $CancelButton #endregion $objCalendar = New-Object System.Windows.Forms.MonthCalendar $objCalendar.ShowTodayCircle = $False $objCalendar.MaxSelectionCount = 1 $objForm.Controls.Add($objCalendar) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) $Results = $objForm.ShowDialog() } Process{} End{ if ($Results -eq "OK") { $objCalendar.SelectionStart } $objForm.Dispose() } }
我正在使用combobox.items.add:
$configCombo.Items.Add($wks) 并且我查找了如何将密钥从打印保持到控制台 – 并将其添加到: [void]$configCombo.Items.Add($wks) 从那时起,我已经添加了这个void – 我已经在ISE中运行了,而且它从未挂起. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 如何在Windows 7上安装PHP 7的MongoDB驱动程序?
- windows-server-2008-r2 – Windows Server 2008
- windows – 为什么调用ProcessGroupPolicyEx回调
- lync – Skype for Business 2016有VDI插件吗?需
- iis-7 – ISAPI .dll作为静态内容提供
- windows-server-2008 – 按用户和登录类型过滤安
- UEFI计算机上的Windows和Linux的映像(例如,使用C
- Windows PATH到bos中的posix路径转换
- windows-server-2008 – GZip压缩在IIS 7.5上无效
- 获取与Windows Vista上的C#.Net连接的无线网络的
热点阅读