Timer 不暂停窗体的Powershell计时器

Timer 不暂停窗体的Powershell计时器,timer,powershell-2.0,Timer,Powershell 2.0,大家好 像往常一样,我被卡住了,我有一个简单的脚本,用于显示bitlocker系统列表的状态。给它一个txt的系统名,它做其余的。所有预期工程;但是,它会在一个滴答作响的计时器上更新列表,执行时会使窗口无响应,并且看起来像是被破坏了(对于那些不了解它在做什么的用户)。有没有办法以某种方式将其分支以避免挂断 我曾考虑过做一个分支,但现在我知道如何使该分支更新其父对象中的对象。。。如果可能的话 代码: 我不敢相信没有人回答这个问题,也许我不清楚 解决方案也很简单,先写输出$object,然后接收作业

大家好

像往常一样,我被卡住了,我有一个简单的脚本,用于显示bitlocker系统列表的状态。给它一个txt的系统名,它做其余的。所有预期工程;但是,它会在一个滴答作响的计时器上更新列表,执行时会使窗口无响应,并且看起来像是被破坏了(对于那些不了解它在做什么的用户)。有没有办法以某种方式将其分支以避免挂断

我曾考虑过做一个分支,但现在我知道如何使该分支更新其父对象中的对象。。。如果可能的话

代码:


我不敢相信没有人回答这个问题,也许我不清楚

解决方案也很简单,先写输出$object,然后接收作业。 完成

[void] [Reflection.Assembly]::LoadWithPartialName( 'System.Windows.Forms' ) 
$d = New-Object Windows.Forms.OpenFileDialog 
$d.ShowHelp = $true 
$d.filter = "System ID List (*.txt)| *.txt"
$result = $d.ShowDialog( )
$names = @()
$names = Get-Content $d.filename

[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")

$myWindow = new-object System.Windows.Forms.form
$myDataGrid = new-object System.windows.forms.DataGridView
$myDataGrid.Location = new-object System.Drawing.Size(20,30)
$myDataGrid.size = new-object System.Drawing.Size(450,480)
$myDataGrid.AllowUserToAddRows = $False
$myDataGrid.AutoSizeColumnsMode = [System.Windows.Forms.DataGridViewAutoSizeColumnsMode]::Fill
$myDataGrid.RowsDefaultCellStyle.BackColor = [System.Drawing.Color]::Bisque
$myDataGrid.AlternatingRowsDefaultCellStyle.BackColor = [System.Drawing.Color]::Beige
$myDataGrid.BorderStyle = [System.Windows.Forms.BorderStyle]::Fixed3D
$myDataGrid.ColumnHeadersDefaultCellSTyle.ForeColor = [System.Drawing.Color]::Maroon
$myDataGrid.ColumnHeadersDefaultCellStyle.BackColor = [System.Drawing.Color]::Tan
$myDataGrid.RowHeadersDefaultCellStyle.BackColor = [System.Drawing.Color]::Tan
$myDataGrid.ColumnHeadersHeightSizeMode = [System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode]::AutoSize
$myWindow.Controls.Add($myDataGrid)


# Define menus
$myMenuStrip = new-object System.Windows.Forms.MenuStrip
$FileExit = new-object System.Windows.Forms.ToolStripMenuItem("&Exit")
$FileExit.add_Click({ $myWindow.close() })
$myMenuStrip.Items.Add($FileMenu)
$myWindow.Controls.Add($myMenuStrip)

$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 1000
$timer.add_tick({
    $dataTable = New-Object System.Data.DataTable            
    $dataTable.Columns.Add("System")  | Out-Null
    $dataTable.Columns.Add("BitLocker % (C:)")   | Out-Null        
    foreach ($name in $names) {
        $stat = (manage-bde.exe -cn $name -status C:)[11].split(":")[1]
        $row = $dataTable.NewRow()
        $row["System"] = $name
        $row["BitLocker % (C:)"]  = $stat
        $dataTable.Rows.Add($row)
    }  
    $myDataGrid.DataSource = $dataTable
})

# main program body
$myWindow.Text = "BitLocker Status"
$myWindow.size = new-object System.Drawing.Size(500,600)
$myWindow.autoscroll = $true
$myWindow.Add_Shown({$myWindow.Activate()})
$timer.Start()
$myWindow.ShowDialog()