Powershell:冻结GUI [英] Powershell: Freezing GUI
问题描述
$ p $
函数循环
{
$ get = read-host
for($ start = 0; $ start -le 100; $ start ++)
{
cls
$ pro_percentage = Get-WmiObject win32_processor -computer $ get -property Loadpercentage |选择loadpercentage
$ percentage =处理器使用率为:+ $ pro_percentage.loadpercentage +%
$百分比
}
}
循环
我还创建了一些GUI,但我注意到一个majour问题,这适用于我创建的其他GUI应用程序。每当按下'go'按钮以从对话框中启动脚本时,GUI将冻结。我在GUI中创建的菜单栏冻结,没有其他按钮可以按下。
我应该在不同的线程中运行每个函数吗?类似的东西?
谢谢 解决方案
尝试添加:
[System.Windows.Forms.Application] :: DoEvents()
在你的循环中。 快速和肮脏,但是。
Just a quick one. I have a problem with a simple tool that I've created that gets the CPU usage for a set amount of time with a small box that appears to display the % of CPU being used (I've stripped out the GUI for the code below).
function loop
{
$get = read-host
for($start = 0; $start -le 100;$start++)
{
cls
$pro_percentage = Get-WmiObject win32_processor -computer $get -property Loadpercentage | select loadpercentage
$percentage = "Processor usage is: " + $pro_percentage.loadpercentage + "%"
$percentage
}
}
loop
There's a few other bits to the GUI that I've created but I've noticed one majour problem, and this goes for other GUI apps that I have created. Whenever the 'go' button is pressed to start the script from the dialog box, the GUI freezes. The menu bar that I've created inside the GUI freezes and no other button can be pressed.
Am I supposed to run each function in a different thread? Something like that?
Thanks
Try to add:
[System.Windows.Forms.Application]::DoEvents()
in your loop. Quick and dirty, however.
这篇关于Powershell:冻结GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!