需要帮助 运行 并行运行
Need help running functions in parallel
我写了一个小的 GUI 脚本,可以从指定位置收集文件,
根据哈希、文件名比较对文件进行分组,并收集零长度文件。
每次按下按钮后。我想做的是将这些按钮组合成一个。
我尝试将按钮脚本块转换为函数。这适用于单一功能。
我知道我需要并行 运行 这些功能,但我相信范围界定存在问题(至少)。我尝试使用 workflow parallel
(我得到 Write Error
)并将每个 scriptblock
分配给后台作业,但我认为因为作业是嵌套的,所以一切都被视为 string object
(双跳?)。
我知道这些可以同时 运行 (我一个接一个地按下,计时器和进度条都出现了)。因此,我们将不胜感激。
Add-Type -AssemblyName System.Windows.Forms
add-type -AssemblyName system.drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$window = New-Object system.Windows.Forms.Form
$window.Height = 450
$window.Width = 400
$window.StartPosition = "CenterScreen"
$window.Font = New-Object System.Drawing.Font("Calibri",11,[System.Drawing.FontStyle]::Bold )
$window.Text = "Duplicates 2.0"
$location = New-Object System.Drawing.Point(10, 10)
$size = New-Object System.Drawing.Size(365, 20)
$ProgressBar1 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar1.Location = New-Object System.Drawing.Point(10, 10)
$ProgressBar1.Size = New-Object System.Drawing.Size(365, 20)
$ProgressBar1.Style = "Marquee"
$ProgressBar1.MarqueeAnimationSpeed = 20
$ProgressBar1.UseWaitCursor = $true
$ProgressBar1.Visible = $false
$button = New-Object System.Windows.Forms.Button
$button.size = New-Object system.drawing.size @(100,50)
$button.Location = New-Object System.Drawing.Point(20, 90)
$button.TextAlign = 'middlecenter'
$button.Text = "Gather `r`n Files"
$window.Controls.add($button)
$label = New-Object System.Windows.Forms.Label
$label.Size = New-Object System.Drawing.Size @(100, 50)
$label.Location = New-Object System.Drawing.Point (135, 90)
$label.BorderStyle = 'Fixed3D'
$label.ForeColor = 'green'
$label.TextAlign = 'middlecenter'
$window.Controls.Add($label)
$check_font = New-Object System.Drawing.Font ("Calibri",20,[System.Drawing.FontStyle]::Bold)
$label3 = New-Object system.windows.forms.label
$label3.Size = New-Object System.Drawing.Size (100, 50)
$label3.Location = New-Object system.drawing.point (250 ,90)
$label3.BorderStyle = 'Fixed3D'
$label3.ForeColor = 'green'
$label3.TextAlign = 'middlecenter'
$label3.Font = $check_font
$window.Controls.Add($label3)
$label4 = New-Object system.windows.forms.label
$label4.Location = New-Object System.Drawing.Point(9, 5)
$label4.Size = New-Object System.Drawing.Size(365, 20)
$label4.TextAlign = 'middlecenter'
$label4.Text = 'COMPLETED!!!'
$label4.Visible = $false
$label4.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label4)
$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 1000
$timer.add_Tick({$script:time2 =((get-date)-$script:time1).ToString("hh\:mm\:ss")
$label.text = $script:time2
})
function rectangle {
$brush = New-Object System.Drawing.SolidBrush ([System.Drawing.Color]::FromArgb(6, 176, 37))
$groupboxGraphics.FillRectangle($brush, 5, 10, 365, 20)
}
$button.add_Click(
{
$Script:time1 = Get-Date
$timer.start()
$ProgressBar1.BringToFront()
$ProgressBar1.Show()
$this.Enabled = $false
$job = Start-Job -ScriptBlock {
Get-ChildItem -File -recurse "Z:\Merck_Peleton" -ErrorAction SilentlyContinue
}
while($job.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job|Wait-job|Receive-Job|Set-Variable -Name PORNO -Scope Script
$groupbox.Controls.Remove($ProgressBar1)
$this.Enabled = $true
$timer.stop()
$label3.Text = [char]8730
$groupbox.Refresh()
rectangle
$label4.Show()
}
)
$label5 = New-Object system.windows.forms.label
$label5.Location = New-Object System.Drawing.Point(9, 35)
$label5.Size = New-Object System.Drawing.Size(365, 20)
$label5.TextAlign = 'middlecenter'
$label5.Text = 'COMPLETED!!!'
$label5.Visible = $false
$label5.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label5)
$button2 = New-Object System.Windows.Forms.Button
$button2.Height = 50
$button2.Width = ($window.Width * 0.85)
$button2.Location = New-Object System.Drawing.Point (20, 350)
$button2.TextAlign = 'middlecenter'
$button2.Text = 'Exit'
$window.Controls.Add($button2)
$ProgressBar2 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar2.Location = New-Object System.Drawing.Point(8, 35)
$ProgressBar2.Size = New-Object System.Drawing.Size(365, 20)
$ProgressBar2.Style = "Marquee"
$ProgressBar2.MarqueeAnimationSpeed = 20
$ProgressBar2.UseWaitCursor = $true
$ProgressBar2.Visible = $false
$button2.add_Click({$window.Close()})
$button3 = new-object System.Windows.Forms.Button
$button3.Size = New-Object System.Drawing.Size (100, 50)
$button3.Location = New-Object System.Drawing.Point (20, 150)
$button3.Text = "Hashes"
$window.Controls.Add($button3)
$timer2 = New-Object System.Windows.Forms.Timer
$timer2.Interval = 1000
$timer2.add_Tick({$script:time4 =((get-date)-$script:time3).ToString("hh\:mm\:ss")
$label2.text = $script:time4
})
$button3.add_Click({
$Script:time3 = Get-Date
$timer2.start()
$ProgressBar2.BringToFront()
$ProgressBar2.Show()
$this.Enabled = $false
$job2 = start-job -scriptblock {
$using:PORNO|Get-FileHash -Algorithm MD5
}
while($job2.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job2|Wait-job|Receive-Job|Set-Variable -Name DUSZNO -Scope Script
$ProgressBar2.Hide()
$groupbox.Controls.Remove($ProgressBar2)
$groupbox.Refresh()
$label5.show()
$this.Enabled = $true
$timer2.stop()
$label6.Text = [char]8730
})
$label2 = New-Object System.Windows.Forms.Label
$label2.size = New-Object System.Drawing.Size (100, 50)
$label2.Location = New-Object System.Drawing.Point (135, 150)
$label2.BorderStyle = 'Fixed3D'
$label2.ForeColor = 'green'
$label2.TextAlign = 'middlecenter'
$window.Controls.Add($label2)
$label6 = new-object System.Windows.Forms.Label
$label6.Size = New-Object System.Drawing.Size (100, 50)
$label6.Location = New-Object System.Drawing.Point (250, 150)
$label6.ForeColor = 'green'
$label6.TextAlign = 'middlecenter'
$label6.Font = $check_font
$label6.BorderStyle = 'Fixed3D'
$window.Controls.Add($label6)
$button4 = New-Object System.Windows.Forms.Button
$button4.size = New-Object System.Drawing.Size (100, 50)
$button4.Location = New-Object System.Drawing.Point (20, 210)
$button4.Text = "Extensions"
$window.Controls.Add($button4)
$timer3 = New-Object System.Windows.Forms.Timer
$timer3.Interval = 1000
$timer3.add_Tick({$script:time6 =((get-date)-$script:time5).ToString("hh\:mm\:ss")
$label7.text = $script:time6
})
$button4.Add_Click({
$Script:time5 = Get-Date
$timer3.start()
$job3 = start-job -scriptblock {
$using:PORNO|
Select @{l="Algorithm";e={}}, @{l="Hash";e={}}, @{l='File';e={$_.PSChildName}}, @{l='Compare Filename';e={$_.BaseName.replace('_','*').replace(' ','*').replace('-','*')}}, @{l="Path";e={$path + $_.PSParentPath.Substring(38,$_.PSParentPath.Length-38)}}, @{l="Link";e={$_.FullName}}, @{l="Extension";e={$_.Extension}}|
group -Property 'Compare Filename'|
Where {@($_.Group.Extension |Sort -Unique).Count -ge 2}
}
while($job3.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job3|Wait-job|Receive-Job|Set-Variable -Name CIASNO -Scope Script
$timer3.Stop()
$label8.Text = [char]8730
})
$label7 = New-Object System.Windows.Forms.Label
$label7.Size = New-Object System.Drawing.Size (100, 50)
$label7.Location = New-Object System.Drawing.Point (135, 210)
$label7.BorderStyle = 'Fixed3D'
$label7.ForeColor = 'green'
$label7.TextAlign = 'middlecenter'
$window.Controls.Add($label7)
$label8 = New-Object System.Windows.Forms.Label
$label8.Size = New-Object System.Drawing.Size (100, 50)
$label8.Location = New-Object System.Drawing.Point (250, 210)
$label8.BorderStyle = 'Fixed3D'
$label8.ForeColor = 'green'
$label8.Font = $check_font
$label8.TextAlign = 'middlecenter'
$window.Controls.Add($label8)
$timer4 = new-object System.Windows.Forms.Timer
$timer4.add_Tick({$script:time8 =((get-date)-$script:time7).ToString("hh\:mm\:ss")
$label9.text = $script:time8
})
$button5 = New-Object System.Windows.Forms.Button
$button5.size = New-Object System.Drawing.Size (100, 50)
$button5.Location = New-Object System.Drawing.Point (20, 270)
$button5.Text = "Zero Length"
$window.Controls.Add($button5)
$button5.Add_Click({
$Script:time7 = Get-Date
$timer4.start()
$job4 = start-job -scriptblock {
$using:PORNO|
? {$_.Length -eq 0}|
Select @{l='File';e={$_.PSChildName}}, Length, Directory, FullName
}
while($job4.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job4|Wait-job|Receive-Job|Set-Variable -Name PRZYJEMNIE -Scope Script
$timer4.Stop()
if ($PRZYJEMNIE -eq $null){$label10.Text = "EMPTY"}else{$label10.Text = [char]8730}
})
$label9 = New-Object System.Windows.Forms.Label
$label9.Size = New-Object System.Drawing.Size (100, 50)
$label9.Location = New-Object System.Drawing.Point (135, 270)
$label9.BorderStyle = 'Fixed3D'
$label9.ForeColor = 'green'
$label9.TextAlign = 'middlecenter'
$window.Controls.Add($label9)
$label10 = New-Object System.Windows.Forms.Label
$label10.Size = New-Object System.Drawing.Size (100,50)
$label10.Location = New-Object System.Drawing.Point (250, 270)
$label10.BorderStyle = 'Fixed3D'
$label10.ForeColor = 'green'
$label10.Font = $check_font
$label10.TextAlign = 'middlecenter'
$window.Controls.Add($label10)
$groupbox = New-Object System.Windows.Forms.GroupBox
$groupbox.size = New-Object system.drawing.size @(377, 413)
$groupbox.Location = New-Object System.Drawing.point (4, -5)
$groupboxGraphics = $groupbox.CreateGraphics()
$groupbox.Controls.Add($ProgressBar1)
$groupbox.Controls.Add($ProgressBar2)
$window.Controls.Add($groupbox)
$window.ShowDialog()|out-null
任何对我如何解决这个问题感兴趣的人。由于我无法同时成功调用两个函数并且嵌套作业对我来说不起作用,所以我转向了其他解决方案。 Timer
因为滴答间隔可以控制并且在每个滴答上可以执行 scriptblock
或 function
我创建了额外的两个计时器(稍后将清理和优化)chceck .status
我想在幕后 运行 的工作。在 fining .state
完成后,它们执行以前是初始按钮脚本的后续部分的功能。我需要处理相对于 'completed' 标签的进度条位置,因为它们不完全 match-up。但在大多数情况下,我实现了我想要的。
更新代码
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName system.drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
Function TEST_1
{
$Script:time1 = Get-Date
$timer.start()
$ProgressBar1.BringToFront()
$ProgressBar1.Show()
$this.Enabled = $false
$job = Start-Job -ScriptBlock {
Get-ChildItem -File -recurse $env:HOMEPATH -ErrorAction SilentlyContinue
}
while($job.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job|Wait-job|Receive-Job|Set-Variable -Name PORNO -Scope Script
$groupbox.Controls.Remove($ProgressBar1)
$this.Enabled = $true
$timer.stop()
$label3.Text = [char]8730
$groupbox.Refresh()
$label4.Show()
}
$window = New-Object system.Windows.Forms.Form
$window.Height = 500
$window.Width = 400
$window.StartPosition = "CenterScreen"
$window.Font = New-Object System.Drawing.Font("Calibri",11,[System.Drawing.FontStyle]::Bold )
$window.Text = "Duplicates 2.0"
$location = New-Object System.Drawing.Point(10, 10)
$size = New-Object System.Drawing.Size(365, 20)
$ProgressBar1 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar1.Location = New-Object System.Drawing.Point(4, 14)
$ProgressBar1.Size = New-Object System.Drawing.Size(364, 20)
$ProgressBar1.Style = "Marquee"
$ProgressBar1.MarqueeAnimationSpeed = 20
$ProgressBar1.UseWaitCursor = $true
$ProgressBar1.Visible = $false
$ProgressBar2 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar2.Location = New-Object System.Drawing.Point(4, 39)
$ProgressBar2.Size = New-Object System.Drawing.Size(364, 20)
$ProgressBar2.Style = "Marquee"
$ProgressBar2.MarqueeAnimationSpeed = 20
$ProgressBar2.UseWaitCursor = $true
$ProgressBar2.Visible = $false
$ProgressBar3 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar3.Location = New-Object System.Drawing.Point(4, 64)
$ProgressBar3.Size = New-Object System.Drawing.Size(364, 20)
$ProgressBar3.Style = "Marquee"
$ProgressBar3.MarqueeAnimationSpeed = 20
$ProgressBar3.UseWaitCursor = $true
$ProgressBar3.Visible = $false
$ProgressBar4 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar4.Location = New-Object System.Drawing.Point(4, 89)
$ProgressBar4.Size = New-Object System.Drawing.Size(364, 20)
$ProgressBar4.Style = "Marquee"
$ProgressBar4.MarqueeAnimationSpeed = 20
$ProgressBar4.UseWaitCursor = $true
$ProgressBar4.Visible = $false
$button = New-Object System.Windows.Forms.Button
$button.size = New-Object system.drawing.size @(100,50)
$button.Location = New-Object System.Drawing.Point(20, 140)
$button.TextAlign = 'middlecenter'
$button.Text = "Gather `r`n Files"
$window.Controls.add($button)
$label = New-Object System.Windows.Forms.Label
$label.Size = New-Object System.Drawing.Size @(100, 50)
$label.Location = New-Object System.Drawing.Point (135, 140)
$label.BorderStyle = 'Fixed3D'
$label.ForeColor = 'green'
$label.TextAlign = 'middlecenter'
$window.Controls.Add($label)
$check_font = New-Object System.Drawing.Font ("Calibri",20,[System.Drawing.FontStyle]::Bold)
$label3 = New-Object system.windows.forms.label
$label3.Size = New-Object System.Drawing.Size (100, 50)
$label3.Location = New-Object system.drawing.point (250 ,140)
$label3.BorderStyle = 'Fixed3D'
$label3.ForeColor = 'green'
$label3.TextAlign = 'middlecenter'
$label3.Font = $check_font
$window.Controls.Add($label3)
$label4 = New-Object system.windows.forms.label
$label4.Location = New-Object System.Drawing.Point(7, 10)
$label4.Size = New-Object System.Drawing.Size(365, 20)
$label4.TextAlign = 'middlecenter'
$label4.Text = 'COMPLETED!!!'
$label4.Visible = $false
$label4.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label4)
$label5 = New-Object system.windows.forms.label
$label5.Location = New-Object System.Drawing.Point(7, 35)
$label5.Size = New-Object System.Drawing.Size(365, 20)
$label5.TextAlign = 'middlecenter'
$label5.Text = 'COMPLETED!!!'
$label5.Visible = $false
$label5.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label5)
$label11 = New-Object system.windows.forms.label
$label11.Location = New-Object System.Drawing.Point(7, 60)
$label11.Size = New-Object System.Drawing.Size(365, 20)
$label11.TextAlign = 'middlecenter'
$label11.Text = 'COMPLETED!!!'
$label11.Visible = $false
$label11.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label11)
$label12 = New-Object system.windows.forms.label
$label12.Location = New-Object System.Drawing.Point(7, 85)
$label12.Size = New-Object System.Drawing.Size(365, 20)
$label12.TextAlign = 'middlecenter'
$label12.Text = 'COMPLETED!!!'
$label12.Visible = $false
$label12.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label12)
$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 1000
$timer.add_Tick({$script:time2 =((get-date)-$script:time1).ToString("hh\:mm\:ss")
$label.text = $script:time2
})
$button.add_Click({TEST_1})
$button2 = New-Object System.Windows.Forms.Button
$button2.Height = 50
$button2.Width = ($window.Width * 0.85)
$button2.Location = New-Object System.Drawing.Point (20, 400)
$button2.TextAlign = 'middlecenter'
$button2.Text = 'Exit'
$window.Controls.Add($button2)
$button2.add_Click({$window.Close()})
$button3 = new-object System.Windows.Forms.Button
$button3.Size = New-Object System.Drawing.Size (100, 50)
$button3.Location = New-Object System.Drawing.Point (20, 200)
$button3.Text = "Hashes"
$window.Controls.Add($button3)
$timer2 = New-Object System.Windows.Forms.Timer
$timer2.Interval = 1000
$timer2.add_Tick({$script:time4 =((get-date)-$script:time3).ToString("hh\:mm\:ss")
$label2.text = $script:time4
})
function W_pizdeczke
{
write-host "W PIZDE!"
}
function W_deseczke2
{
$ProgressBar3.Hide()
$groupbox.Controls.Remove($ProgressBar3)
$groupbox.Refresh()
$label11.show()
$button4.Enabled = $true
$timer3.stop()
$button4_timer.stop()
$label8.Text = "Kurwo"
}
function W_deseczke
{
$ProgressBar2.Hide()
$groupbox.Controls.Remove($ProgressBar2)
$groupbox.Refresh()
$label5.show()
$button3.Enabled = $true
$timer2.stop()
$button3_timer.stop()
$label6.Text = "Udało się"
}
$button3_timer = new-object system.windows.forms.timer
$button3_timer.Interval = 1000
$button3_timer.add_Tick({
$ticker = (get-job -name TESTOWA).state
if ($ticker -eq 'Completed'){W_deseczke}
})
$button4_timer = new-object system.windows.forms.timer
$button4_timer.Interval = 1000
$button4_timer.add_Tick({
$ticker2 = (get-job -name TESTOWA2).state
if ($ticker2 -eq 'Completed'){W_deseczke2}
})
$button3.add_Click({
$button3_timer.Start()
$button4_timer.Start()
$Script:time3 = Get-Date
$Script:time5 = Get-Date
$timer2.start()
$timer3.start()
$ProgressBar2.BringToFront()
$ProgressBar2.Show()
$ProgressBar3.BringToFront()
$ProgressBar3.Show()
$this.Enabled = $false
$button4.enabled= $false
$job2 = start-job -Name "TESTOWA" -scriptblock {
$using:PORNO|
Get-FileHash -Algorithm MD5
}
$job3 = start-job -Name "TESTOWA2" -scriptblock {
$using:PORNO|
Select @{l="Algorithm";e={}}, @{l="Hash";e={}}, @{l='File';e={$_.PSChildName}}, @{l='Compare Filename';e={$_.BaseName.replace('_','*').replace(' ','*').replace('-','*')}}, @{l="Path";e={$path + $_.PSParentPath.Substring(38,$_.PSParentPath.Length-38)}}, @{l="Link";e={$_.FullName}}, @{l="Extension";e={$_.Extension}}|
group -Property 'Compare Filename'|
Where {@($_.Group.Extension |Sort -Unique).Count -ge 2}
}
while(($job2.State -eq 'Running') -or ($job3.state -eq 'Running')) {
[System.Windows.Forms.Application]::DoEvents()
}
$job2|Wait-job|Receive-Job|Set-Variable -Name DUSZNO -Scope Script
$job3|Wait-job|Receive-Job|Set-Variable -Name CIASNO -Scope Script
})
$label2 = New-Object System.Windows.Forms.Label
$label2.size = New-Object System.Drawing.Size (100, 50)
$label2.Location = New-Object System.Drawing.Point (135, 200)
$label2.BorderStyle = 'Fixed3D'
$label2.ForeColor = 'green'
$label2.TextAlign = 'middlecenter'
$window.Controls.Add($label2)
$label6 = new-object System.Windows.Forms.Label
$label6.Size = New-Object System.Drawing.Size (100, 50)
$label6.Location = New-Object System.Drawing.Point (250, 200)
$label6.ForeColor = 'green'
$label6.TextAlign = 'middlecenter'
$label6.Font = $check_font
$label6.BorderStyle = 'Fixed3D'
$window.Controls.Add($label6)
$button4 = New-Object System.Windows.Forms.Button
$button4.size = New-Object System.Drawing.Size (100, 50)
$button4.Location = New-Object System.Drawing.Point (20, 260)
$button4.Text = "Extensions"
$window.Controls.Add($button4)
$timer3 = New-Object System.Windows.Forms.Timer
$timer3.Interval = 1000
$timer3.add_Tick({$script:time6 =((get-date)-$script:time5).ToString("hh\:mm\:ss")
$label7.text = $script:time6
})
$button4.Add_Click({
})
$label7 = New-Object System.Windows.Forms.Label
$label7.Size = New-Object System.Drawing.Size (100, 50)
$label7.Location = New-Object System.Drawing.Point (135, 260)
$label7.BorderStyle = 'Fixed3D'
$label7.ForeColor = 'green'
$label7.TextAlign = 'middlecenter'
$window.Controls.Add($label7)
$label8 = New-Object System.Windows.Forms.Label
$label8.Size = New-Object System.Drawing.Size (100, 50)
$label8.Location = New-Object System.Drawing.Point (250, 260)
$label8.BorderStyle = 'Fixed3D'
$label8.ForeColor = 'green'
$label8.Font = $check_font
$label8.TextAlign = 'middlecenter'
$window.Controls.Add($label8)
$timer4 = new-object System.Windows.Forms.Timer
$timer4.add_Tick({$script:time8 =((get-date)-$script:time7).ToString("hh\:mm\:ss")
$label9.text = $script:time8
})
$button5 = New-Object System.Windows.Forms.Button
$button5.size = New-Object System.Drawing.Size (100, 50)
$button5.Location = New-Object System.Drawing.Point (20, 320)
$button5.Text = "Zero Length"
$window.Controls.Add($button5)
$button5.Add_Click({
$Script:time7 = Get-Date
$timer4.start()
$job4 = start-job -scriptblock {
$using:PORNO|
? {$_.Length -eq 0}|
Select @{l='File';e={$_.PSChildName}}, Length, Directory, FullName
}
while($job4.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job4|Wait-job|Receive-Job|Set-Variable -Name PRZYJEMNIE -Scope Script
$timer4.Stop()
if ($PRZYJEMNIE -eq $null){$label10.Text = "EMPTY"}else{$label10.Text = [char]8730}
})
$label9 = New-Object System.Windows.Forms.Label
$label9.Size = New-Object System.Drawing.Size (100, 50)
$label9.Location = New-Object System.Drawing.Point (135, 320)
$label9.BorderStyle = 'Fixed3D'
$label9.ForeColor = 'green'
$label9.TextAlign = 'middlecenter'
$window.Controls.Add($label9)
$label10 = New-Object System.Windows.Forms.Label
$label10.Size = New-Object System.Drawing.Size (100,50)
$label10.Location = New-Object System.Drawing.Point (250, 320)
$label10.BorderStyle = 'Fixed3D'
$label10.ForeColor = 'green'
$label10.Font = $check_font
$label10.TextAlign = 'middlecenter'
$window.Controls.Add($label10)
$groupbox = New-Object System.Windows.Forms.GroupBox
$groupbox.size = New-Object system.drawing.size @(377, 413)
$groupbox.Location = New-Object System.Drawing.point (4, -5)
$groupboxGraphics = $groupbox.CreateGraphics()
$groupbox.Controls.Add($ProgressBar1)
$groupbox.Controls.Add($ProgressBar2)
$groupbox.Controls.Add($ProgressBar3)
$groupbox.Controls.Add($ProgressBar4)
$window.Controls.Add($groupbox)
$window.ShowDialog()|out-null
我写了一个小的 GUI 脚本,可以从指定位置收集文件,
根据哈希、文件名比较对文件进行分组,并收集零长度文件。
每次按下按钮后。我想做的是将这些按钮组合成一个。
我尝试将按钮脚本块转换为函数。这适用于单一功能。
我知道我需要并行 运行 这些功能,但我相信范围界定存在问题(至少)。我尝试使用 workflow parallel
(我得到 Write Error
)并将每个 scriptblock
分配给后台作业,但我认为因为作业是嵌套的,所以一切都被视为 string object
(双跳?)。
我知道这些可以同时 运行 (我一个接一个地按下,计时器和进度条都出现了)。因此,我们将不胜感激。
Add-Type -AssemblyName System.Windows.Forms
add-type -AssemblyName system.drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$window = New-Object system.Windows.Forms.Form
$window.Height = 450
$window.Width = 400
$window.StartPosition = "CenterScreen"
$window.Font = New-Object System.Drawing.Font("Calibri",11,[System.Drawing.FontStyle]::Bold )
$window.Text = "Duplicates 2.0"
$location = New-Object System.Drawing.Point(10, 10)
$size = New-Object System.Drawing.Size(365, 20)
$ProgressBar1 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar1.Location = New-Object System.Drawing.Point(10, 10)
$ProgressBar1.Size = New-Object System.Drawing.Size(365, 20)
$ProgressBar1.Style = "Marquee"
$ProgressBar1.MarqueeAnimationSpeed = 20
$ProgressBar1.UseWaitCursor = $true
$ProgressBar1.Visible = $false
$button = New-Object System.Windows.Forms.Button
$button.size = New-Object system.drawing.size @(100,50)
$button.Location = New-Object System.Drawing.Point(20, 90)
$button.TextAlign = 'middlecenter'
$button.Text = "Gather `r`n Files"
$window.Controls.add($button)
$label = New-Object System.Windows.Forms.Label
$label.Size = New-Object System.Drawing.Size @(100, 50)
$label.Location = New-Object System.Drawing.Point (135, 90)
$label.BorderStyle = 'Fixed3D'
$label.ForeColor = 'green'
$label.TextAlign = 'middlecenter'
$window.Controls.Add($label)
$check_font = New-Object System.Drawing.Font ("Calibri",20,[System.Drawing.FontStyle]::Bold)
$label3 = New-Object system.windows.forms.label
$label3.Size = New-Object System.Drawing.Size (100, 50)
$label3.Location = New-Object system.drawing.point (250 ,90)
$label3.BorderStyle = 'Fixed3D'
$label3.ForeColor = 'green'
$label3.TextAlign = 'middlecenter'
$label3.Font = $check_font
$window.Controls.Add($label3)
$label4 = New-Object system.windows.forms.label
$label4.Location = New-Object System.Drawing.Point(9, 5)
$label4.Size = New-Object System.Drawing.Size(365, 20)
$label4.TextAlign = 'middlecenter'
$label4.Text = 'COMPLETED!!!'
$label4.Visible = $false
$label4.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label4)
$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 1000
$timer.add_Tick({$script:time2 =((get-date)-$script:time1).ToString("hh\:mm\:ss")
$label.text = $script:time2
})
function rectangle {
$brush = New-Object System.Drawing.SolidBrush ([System.Drawing.Color]::FromArgb(6, 176, 37))
$groupboxGraphics.FillRectangle($brush, 5, 10, 365, 20)
}
$button.add_Click(
{
$Script:time1 = Get-Date
$timer.start()
$ProgressBar1.BringToFront()
$ProgressBar1.Show()
$this.Enabled = $false
$job = Start-Job -ScriptBlock {
Get-ChildItem -File -recurse "Z:\Merck_Peleton" -ErrorAction SilentlyContinue
}
while($job.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job|Wait-job|Receive-Job|Set-Variable -Name PORNO -Scope Script
$groupbox.Controls.Remove($ProgressBar1)
$this.Enabled = $true
$timer.stop()
$label3.Text = [char]8730
$groupbox.Refresh()
rectangle
$label4.Show()
}
)
$label5 = New-Object system.windows.forms.label
$label5.Location = New-Object System.Drawing.Point(9, 35)
$label5.Size = New-Object System.Drawing.Size(365, 20)
$label5.TextAlign = 'middlecenter'
$label5.Text = 'COMPLETED!!!'
$label5.Visible = $false
$label5.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label5)
$button2 = New-Object System.Windows.Forms.Button
$button2.Height = 50
$button2.Width = ($window.Width * 0.85)
$button2.Location = New-Object System.Drawing.Point (20, 350)
$button2.TextAlign = 'middlecenter'
$button2.Text = 'Exit'
$window.Controls.Add($button2)
$ProgressBar2 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar2.Location = New-Object System.Drawing.Point(8, 35)
$ProgressBar2.Size = New-Object System.Drawing.Size(365, 20)
$ProgressBar2.Style = "Marquee"
$ProgressBar2.MarqueeAnimationSpeed = 20
$ProgressBar2.UseWaitCursor = $true
$ProgressBar2.Visible = $false
$button2.add_Click({$window.Close()})
$button3 = new-object System.Windows.Forms.Button
$button3.Size = New-Object System.Drawing.Size (100, 50)
$button3.Location = New-Object System.Drawing.Point (20, 150)
$button3.Text = "Hashes"
$window.Controls.Add($button3)
$timer2 = New-Object System.Windows.Forms.Timer
$timer2.Interval = 1000
$timer2.add_Tick({$script:time4 =((get-date)-$script:time3).ToString("hh\:mm\:ss")
$label2.text = $script:time4
})
$button3.add_Click({
$Script:time3 = Get-Date
$timer2.start()
$ProgressBar2.BringToFront()
$ProgressBar2.Show()
$this.Enabled = $false
$job2 = start-job -scriptblock {
$using:PORNO|Get-FileHash -Algorithm MD5
}
while($job2.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job2|Wait-job|Receive-Job|Set-Variable -Name DUSZNO -Scope Script
$ProgressBar2.Hide()
$groupbox.Controls.Remove($ProgressBar2)
$groupbox.Refresh()
$label5.show()
$this.Enabled = $true
$timer2.stop()
$label6.Text = [char]8730
})
$label2 = New-Object System.Windows.Forms.Label
$label2.size = New-Object System.Drawing.Size (100, 50)
$label2.Location = New-Object System.Drawing.Point (135, 150)
$label2.BorderStyle = 'Fixed3D'
$label2.ForeColor = 'green'
$label2.TextAlign = 'middlecenter'
$window.Controls.Add($label2)
$label6 = new-object System.Windows.Forms.Label
$label6.Size = New-Object System.Drawing.Size (100, 50)
$label6.Location = New-Object System.Drawing.Point (250, 150)
$label6.ForeColor = 'green'
$label6.TextAlign = 'middlecenter'
$label6.Font = $check_font
$label6.BorderStyle = 'Fixed3D'
$window.Controls.Add($label6)
$button4 = New-Object System.Windows.Forms.Button
$button4.size = New-Object System.Drawing.Size (100, 50)
$button4.Location = New-Object System.Drawing.Point (20, 210)
$button4.Text = "Extensions"
$window.Controls.Add($button4)
$timer3 = New-Object System.Windows.Forms.Timer
$timer3.Interval = 1000
$timer3.add_Tick({$script:time6 =((get-date)-$script:time5).ToString("hh\:mm\:ss")
$label7.text = $script:time6
})
$button4.Add_Click({
$Script:time5 = Get-Date
$timer3.start()
$job3 = start-job -scriptblock {
$using:PORNO|
Select @{l="Algorithm";e={}}, @{l="Hash";e={}}, @{l='File';e={$_.PSChildName}}, @{l='Compare Filename';e={$_.BaseName.replace('_','*').replace(' ','*').replace('-','*')}}, @{l="Path";e={$path + $_.PSParentPath.Substring(38,$_.PSParentPath.Length-38)}}, @{l="Link";e={$_.FullName}}, @{l="Extension";e={$_.Extension}}|
group -Property 'Compare Filename'|
Where {@($_.Group.Extension |Sort -Unique).Count -ge 2}
}
while($job3.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job3|Wait-job|Receive-Job|Set-Variable -Name CIASNO -Scope Script
$timer3.Stop()
$label8.Text = [char]8730
})
$label7 = New-Object System.Windows.Forms.Label
$label7.Size = New-Object System.Drawing.Size (100, 50)
$label7.Location = New-Object System.Drawing.Point (135, 210)
$label7.BorderStyle = 'Fixed3D'
$label7.ForeColor = 'green'
$label7.TextAlign = 'middlecenter'
$window.Controls.Add($label7)
$label8 = New-Object System.Windows.Forms.Label
$label8.Size = New-Object System.Drawing.Size (100, 50)
$label8.Location = New-Object System.Drawing.Point (250, 210)
$label8.BorderStyle = 'Fixed3D'
$label8.ForeColor = 'green'
$label8.Font = $check_font
$label8.TextAlign = 'middlecenter'
$window.Controls.Add($label8)
$timer4 = new-object System.Windows.Forms.Timer
$timer4.add_Tick({$script:time8 =((get-date)-$script:time7).ToString("hh\:mm\:ss")
$label9.text = $script:time8
})
$button5 = New-Object System.Windows.Forms.Button
$button5.size = New-Object System.Drawing.Size (100, 50)
$button5.Location = New-Object System.Drawing.Point (20, 270)
$button5.Text = "Zero Length"
$window.Controls.Add($button5)
$button5.Add_Click({
$Script:time7 = Get-Date
$timer4.start()
$job4 = start-job -scriptblock {
$using:PORNO|
? {$_.Length -eq 0}|
Select @{l='File';e={$_.PSChildName}}, Length, Directory, FullName
}
while($job4.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job4|Wait-job|Receive-Job|Set-Variable -Name PRZYJEMNIE -Scope Script
$timer4.Stop()
if ($PRZYJEMNIE -eq $null){$label10.Text = "EMPTY"}else{$label10.Text = [char]8730}
})
$label9 = New-Object System.Windows.Forms.Label
$label9.Size = New-Object System.Drawing.Size (100, 50)
$label9.Location = New-Object System.Drawing.Point (135, 270)
$label9.BorderStyle = 'Fixed3D'
$label9.ForeColor = 'green'
$label9.TextAlign = 'middlecenter'
$window.Controls.Add($label9)
$label10 = New-Object System.Windows.Forms.Label
$label10.Size = New-Object System.Drawing.Size (100,50)
$label10.Location = New-Object System.Drawing.Point (250, 270)
$label10.BorderStyle = 'Fixed3D'
$label10.ForeColor = 'green'
$label10.Font = $check_font
$label10.TextAlign = 'middlecenter'
$window.Controls.Add($label10)
$groupbox = New-Object System.Windows.Forms.GroupBox
$groupbox.size = New-Object system.drawing.size @(377, 413)
$groupbox.Location = New-Object System.Drawing.point (4, -5)
$groupboxGraphics = $groupbox.CreateGraphics()
$groupbox.Controls.Add($ProgressBar1)
$groupbox.Controls.Add($ProgressBar2)
$window.Controls.Add($groupbox)
$window.ShowDialog()|out-null
任何对我如何解决这个问题感兴趣的人。由于我无法同时成功调用两个函数并且嵌套作业对我来说不起作用,所以我转向了其他解决方案。 Timer
因为滴答间隔可以控制并且在每个滴答上可以执行 scriptblock
或 function
我创建了额外的两个计时器(稍后将清理和优化)chceck .status
我想在幕后 运行 的工作。在 fining .state
完成后,它们执行以前是初始按钮脚本的后续部分的功能。我需要处理相对于 'completed' 标签的进度条位置,因为它们不完全 match-up。但在大多数情况下,我实现了我想要的。
更新代码
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName system.drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
Function TEST_1
{
$Script:time1 = Get-Date
$timer.start()
$ProgressBar1.BringToFront()
$ProgressBar1.Show()
$this.Enabled = $false
$job = Start-Job -ScriptBlock {
Get-ChildItem -File -recurse $env:HOMEPATH -ErrorAction SilentlyContinue
}
while($job.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job|Wait-job|Receive-Job|Set-Variable -Name PORNO -Scope Script
$groupbox.Controls.Remove($ProgressBar1)
$this.Enabled = $true
$timer.stop()
$label3.Text = [char]8730
$groupbox.Refresh()
$label4.Show()
}
$window = New-Object system.Windows.Forms.Form
$window.Height = 500
$window.Width = 400
$window.StartPosition = "CenterScreen"
$window.Font = New-Object System.Drawing.Font("Calibri",11,[System.Drawing.FontStyle]::Bold )
$window.Text = "Duplicates 2.0"
$location = New-Object System.Drawing.Point(10, 10)
$size = New-Object System.Drawing.Size(365, 20)
$ProgressBar1 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar1.Location = New-Object System.Drawing.Point(4, 14)
$ProgressBar1.Size = New-Object System.Drawing.Size(364, 20)
$ProgressBar1.Style = "Marquee"
$ProgressBar1.MarqueeAnimationSpeed = 20
$ProgressBar1.UseWaitCursor = $true
$ProgressBar1.Visible = $false
$ProgressBar2 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar2.Location = New-Object System.Drawing.Point(4, 39)
$ProgressBar2.Size = New-Object System.Drawing.Size(364, 20)
$ProgressBar2.Style = "Marquee"
$ProgressBar2.MarqueeAnimationSpeed = 20
$ProgressBar2.UseWaitCursor = $true
$ProgressBar2.Visible = $false
$ProgressBar3 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar3.Location = New-Object System.Drawing.Point(4, 64)
$ProgressBar3.Size = New-Object System.Drawing.Size(364, 20)
$ProgressBar3.Style = "Marquee"
$ProgressBar3.MarqueeAnimationSpeed = 20
$ProgressBar3.UseWaitCursor = $true
$ProgressBar3.Visible = $false
$ProgressBar4 = New-Object System.Windows.Forms.ProgressBar
$ProgressBar4.Location = New-Object System.Drawing.Point(4, 89)
$ProgressBar4.Size = New-Object System.Drawing.Size(364, 20)
$ProgressBar4.Style = "Marquee"
$ProgressBar4.MarqueeAnimationSpeed = 20
$ProgressBar4.UseWaitCursor = $true
$ProgressBar4.Visible = $false
$button = New-Object System.Windows.Forms.Button
$button.size = New-Object system.drawing.size @(100,50)
$button.Location = New-Object System.Drawing.Point(20, 140)
$button.TextAlign = 'middlecenter'
$button.Text = "Gather `r`n Files"
$window.Controls.add($button)
$label = New-Object System.Windows.Forms.Label
$label.Size = New-Object System.Drawing.Size @(100, 50)
$label.Location = New-Object System.Drawing.Point (135, 140)
$label.BorderStyle = 'Fixed3D'
$label.ForeColor = 'green'
$label.TextAlign = 'middlecenter'
$window.Controls.Add($label)
$check_font = New-Object System.Drawing.Font ("Calibri",20,[System.Drawing.FontStyle]::Bold)
$label3 = New-Object system.windows.forms.label
$label3.Size = New-Object System.Drawing.Size (100, 50)
$label3.Location = New-Object system.drawing.point (250 ,140)
$label3.BorderStyle = 'Fixed3D'
$label3.ForeColor = 'green'
$label3.TextAlign = 'middlecenter'
$label3.Font = $check_font
$window.Controls.Add($label3)
$label4 = New-Object system.windows.forms.label
$label4.Location = New-Object System.Drawing.Point(7, 10)
$label4.Size = New-Object System.Drawing.Size(365, 20)
$label4.TextAlign = 'middlecenter'
$label4.Text = 'COMPLETED!!!'
$label4.Visible = $false
$label4.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label4)
$label5 = New-Object system.windows.forms.label
$label5.Location = New-Object System.Drawing.Point(7, 35)
$label5.Size = New-Object System.Drawing.Size(365, 20)
$label5.TextAlign = 'middlecenter'
$label5.Text = 'COMPLETED!!!'
$label5.Visible = $false
$label5.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label5)
$label11 = New-Object system.windows.forms.label
$label11.Location = New-Object System.Drawing.Point(7, 60)
$label11.Size = New-Object System.Drawing.Size(365, 20)
$label11.TextAlign = 'middlecenter'
$label11.Text = 'COMPLETED!!!'
$label11.Visible = $false
$label11.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label11)
$label12 = New-Object system.windows.forms.label
$label12.Location = New-Object System.Drawing.Point(7, 85)
$label12.Size = New-Object System.Drawing.Size(365, 20)
$label12.TextAlign = 'middlecenter'
$label12.Text = 'COMPLETED!!!'
$label12.Visible = $false
$label12.BackColor = [System.Drawing.Color]::FromArgb(6, 176, 37)
$window.Controls.Add($label12)
$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 1000
$timer.add_Tick({$script:time2 =((get-date)-$script:time1).ToString("hh\:mm\:ss")
$label.text = $script:time2
})
$button.add_Click({TEST_1})
$button2 = New-Object System.Windows.Forms.Button
$button2.Height = 50
$button2.Width = ($window.Width * 0.85)
$button2.Location = New-Object System.Drawing.Point (20, 400)
$button2.TextAlign = 'middlecenter'
$button2.Text = 'Exit'
$window.Controls.Add($button2)
$button2.add_Click({$window.Close()})
$button3 = new-object System.Windows.Forms.Button
$button3.Size = New-Object System.Drawing.Size (100, 50)
$button3.Location = New-Object System.Drawing.Point (20, 200)
$button3.Text = "Hashes"
$window.Controls.Add($button3)
$timer2 = New-Object System.Windows.Forms.Timer
$timer2.Interval = 1000
$timer2.add_Tick({$script:time4 =((get-date)-$script:time3).ToString("hh\:mm\:ss")
$label2.text = $script:time4
})
function W_pizdeczke
{
write-host "W PIZDE!"
}
function W_deseczke2
{
$ProgressBar3.Hide()
$groupbox.Controls.Remove($ProgressBar3)
$groupbox.Refresh()
$label11.show()
$button4.Enabled = $true
$timer3.stop()
$button4_timer.stop()
$label8.Text = "Kurwo"
}
function W_deseczke
{
$ProgressBar2.Hide()
$groupbox.Controls.Remove($ProgressBar2)
$groupbox.Refresh()
$label5.show()
$button3.Enabled = $true
$timer2.stop()
$button3_timer.stop()
$label6.Text = "Udało się"
}
$button3_timer = new-object system.windows.forms.timer
$button3_timer.Interval = 1000
$button3_timer.add_Tick({
$ticker = (get-job -name TESTOWA).state
if ($ticker -eq 'Completed'){W_deseczke}
})
$button4_timer = new-object system.windows.forms.timer
$button4_timer.Interval = 1000
$button4_timer.add_Tick({
$ticker2 = (get-job -name TESTOWA2).state
if ($ticker2 -eq 'Completed'){W_deseczke2}
})
$button3.add_Click({
$button3_timer.Start()
$button4_timer.Start()
$Script:time3 = Get-Date
$Script:time5 = Get-Date
$timer2.start()
$timer3.start()
$ProgressBar2.BringToFront()
$ProgressBar2.Show()
$ProgressBar3.BringToFront()
$ProgressBar3.Show()
$this.Enabled = $false
$button4.enabled= $false
$job2 = start-job -Name "TESTOWA" -scriptblock {
$using:PORNO|
Get-FileHash -Algorithm MD5
}
$job3 = start-job -Name "TESTOWA2" -scriptblock {
$using:PORNO|
Select @{l="Algorithm";e={}}, @{l="Hash";e={}}, @{l='File';e={$_.PSChildName}}, @{l='Compare Filename';e={$_.BaseName.replace('_','*').replace(' ','*').replace('-','*')}}, @{l="Path";e={$path + $_.PSParentPath.Substring(38,$_.PSParentPath.Length-38)}}, @{l="Link";e={$_.FullName}}, @{l="Extension";e={$_.Extension}}|
group -Property 'Compare Filename'|
Where {@($_.Group.Extension |Sort -Unique).Count -ge 2}
}
while(($job2.State -eq 'Running') -or ($job3.state -eq 'Running')) {
[System.Windows.Forms.Application]::DoEvents()
}
$job2|Wait-job|Receive-Job|Set-Variable -Name DUSZNO -Scope Script
$job3|Wait-job|Receive-Job|Set-Variable -Name CIASNO -Scope Script
})
$label2 = New-Object System.Windows.Forms.Label
$label2.size = New-Object System.Drawing.Size (100, 50)
$label2.Location = New-Object System.Drawing.Point (135, 200)
$label2.BorderStyle = 'Fixed3D'
$label2.ForeColor = 'green'
$label2.TextAlign = 'middlecenter'
$window.Controls.Add($label2)
$label6 = new-object System.Windows.Forms.Label
$label6.Size = New-Object System.Drawing.Size (100, 50)
$label6.Location = New-Object System.Drawing.Point (250, 200)
$label6.ForeColor = 'green'
$label6.TextAlign = 'middlecenter'
$label6.Font = $check_font
$label6.BorderStyle = 'Fixed3D'
$window.Controls.Add($label6)
$button4 = New-Object System.Windows.Forms.Button
$button4.size = New-Object System.Drawing.Size (100, 50)
$button4.Location = New-Object System.Drawing.Point (20, 260)
$button4.Text = "Extensions"
$window.Controls.Add($button4)
$timer3 = New-Object System.Windows.Forms.Timer
$timer3.Interval = 1000
$timer3.add_Tick({$script:time6 =((get-date)-$script:time5).ToString("hh\:mm\:ss")
$label7.text = $script:time6
})
$button4.Add_Click({
})
$label7 = New-Object System.Windows.Forms.Label
$label7.Size = New-Object System.Drawing.Size (100, 50)
$label7.Location = New-Object System.Drawing.Point (135, 260)
$label7.BorderStyle = 'Fixed3D'
$label7.ForeColor = 'green'
$label7.TextAlign = 'middlecenter'
$window.Controls.Add($label7)
$label8 = New-Object System.Windows.Forms.Label
$label8.Size = New-Object System.Drawing.Size (100, 50)
$label8.Location = New-Object System.Drawing.Point (250, 260)
$label8.BorderStyle = 'Fixed3D'
$label8.ForeColor = 'green'
$label8.Font = $check_font
$label8.TextAlign = 'middlecenter'
$window.Controls.Add($label8)
$timer4 = new-object System.Windows.Forms.Timer
$timer4.add_Tick({$script:time8 =((get-date)-$script:time7).ToString("hh\:mm\:ss")
$label9.text = $script:time8
})
$button5 = New-Object System.Windows.Forms.Button
$button5.size = New-Object System.Drawing.Size (100, 50)
$button5.Location = New-Object System.Drawing.Point (20, 320)
$button5.Text = "Zero Length"
$window.Controls.Add($button5)
$button5.Add_Click({
$Script:time7 = Get-Date
$timer4.start()
$job4 = start-job -scriptblock {
$using:PORNO|
? {$_.Length -eq 0}|
Select @{l='File';e={$_.PSChildName}}, Length, Directory, FullName
}
while($job4.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job4|Wait-job|Receive-Job|Set-Variable -Name PRZYJEMNIE -Scope Script
$timer4.Stop()
if ($PRZYJEMNIE -eq $null){$label10.Text = "EMPTY"}else{$label10.Text = [char]8730}
})
$label9 = New-Object System.Windows.Forms.Label
$label9.Size = New-Object System.Drawing.Size (100, 50)
$label9.Location = New-Object System.Drawing.Point (135, 320)
$label9.BorderStyle = 'Fixed3D'
$label9.ForeColor = 'green'
$label9.TextAlign = 'middlecenter'
$window.Controls.Add($label9)
$label10 = New-Object System.Windows.Forms.Label
$label10.Size = New-Object System.Drawing.Size (100,50)
$label10.Location = New-Object System.Drawing.Point (250, 320)
$label10.BorderStyle = 'Fixed3D'
$label10.ForeColor = 'green'
$label10.Font = $check_font
$label10.TextAlign = 'middlecenter'
$window.Controls.Add($label10)
$groupbox = New-Object System.Windows.Forms.GroupBox
$groupbox.size = New-Object system.drawing.size @(377, 413)
$groupbox.Location = New-Object System.Drawing.point (4, -5)
$groupboxGraphics = $groupbox.CreateGraphics()
$groupbox.Controls.Add($ProgressBar1)
$groupbox.Controls.Add($ProgressBar2)
$groupbox.Controls.Add($ProgressBar3)
$groupbox.Controls.Add($ProgressBar4)
$window.Controls.Add($groupbox)
$window.ShowDialog()|out-null