我可以開始工作,但是如何在獲取信息時如何繼續使用我的程序?凍結程序直到結果完成。Start-Job Receive-Job在獲取結果時掛起/凍結 - PrimalForm CE GUI
這裏是PrimalForms CE版本生成的腳本,我的代碼在button1_OnClick
。
最終結果我想讓腳本運行來檢查鎖定的AD用戶(但那真的可以是任何東西),然後在運行時我想查看先前的結果並在需要時解鎖用戶...
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 7/09/2015 2:24 PM
# Generated By: stojanp2
########################################################################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$button3 = New-Object System.Windows.Forms.Button
$button2 = New-Object System.Windows.Forms.Button
$listView1 = New-Object System.Windows.Forms.ListView
$button1 = New-Object System.Windows.Forms.Button
$Users = New-Object System.Windows.Forms.ColumnHeader
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button3_OnClick =
{
#TODO: Place custom script here
}
$button1_OnClick =
{
Start-Job -Name FindUsers -ScriptBlock { Search-ADAccount -LockedOut | Select-Object * }#end Start-Job
Do {
Start-Sleep -Seconds 1
write-host "waiting" # so i can see its doing something in the console
} Until (@(Get-Job -Name FindUsers).State -eq "Completed")
Write-Host "done"
$us = Receive-Job -Name FindUsers
ForEach ($u IN $us){
$listView1.Items.Add($u.sAMAccountName)
}
Get-Job -Name FindUsers | Remove-Job -Force
}
$button2_OnClick =
{
#TODO: Place custom script here
}
$handler_listView1_SelectedIndexChanged =
{
#TODO: Place custom script here
}
$OnLoadForm_StateCorrection =
{ #Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 469
$System_Drawing_Size.Width = 271
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Primal Form"
$button3.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 142
$System_Drawing_Point.Y = 418
$button3.Location = $System_Drawing_Point
$button3.Name = "button3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 117
$button3.Size = $System_Drawing_Size
$button3.TabIndex = 3
$button3.Text = "button3"
$button3.UseVisualStyleBackColor = $True
$button3.add_Click($button3_OnClick)
$form1.Controls.Add($button3)
$button2.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 418
$button2.Location = $System_Drawing_Point
$button2.Name
= "button2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 117
$button2.Size = $System_Drawing_Size
$button2.TabIndex = 2
$button2.Text = "button2"
$button2.UseVisualStyleBackColor = $True
$button2.add_Click($button2_OnClick)
$form1.Controls.Add($button2)
$listView1.Columns.Add($Users)|Out-Null
$listView1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 73
$listView1.Location = $System_Drawing_Point
$listView1.Name = "listView1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 339
$System_Drawing_Size.Width = 247
$listView1.Size = $System_Drawing_Size
$listView1.TabIndex = 1
$listView1.UseCompatibleStateImageBehavior = $False
$listView1.View = 1
$listView1.add_SelectedIndexChanged($handler_listView1_SelectedIndexChanged)
$form1.Controls.Add($listView1)
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 12
$button1.Location = $System_Drawing_Point
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 55
$System_Drawing_Size.Width = 247
$button1.Size = $System_Drawing_Size
$button1.TabIndex = 0
$button1.Text = "button1"
$button1.UseVisualStyleBackColor = $True
$button1.add_Click($button1_OnClick)
$form1.Controls.Add($button1)
$Users.Name = "Users"
$Users.Text = "User Names"
$Users.Width = 116
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog() | Out-Null
} #End Function
#Call the Function
GenerateForm