Bya*_*aku 2 powershell performance
我制作了一个同时启动多个后台作业的程序.目前,该过程需要几个小时(有时3小时,有时长达6小时,具体取决于文件和大小).
重写代码是否有任何优势,因此它不会使用Background-Jobs启动同一Shell中的所有进程,而是为每个单独的进程启动PowerShell?或者两者之间没有什么大不同?
$handler_button1_Click=
{
if ($checkBox1.Checked) {
Try{
$job1 = start-jobhere {& C:\Users\mosermich\Desktop\Extractor\Ressources\adp_staging.bat} -Name "ADP-DATA"
$listBox1.Items.Add("ADP-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox2.Checked) {
Try{
$job2 = start-jobhere {& C:\Users\mosermich\Desktop\Extractor\Ressources\kdp_staging.bat} -Name "KDP-DATA"
$listBox1.Items.Add("KDP-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox3.Checked) {
Try{
$job3 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\mdp_staging.bat} -Name "MDP-DATA"
$listBox1.Items.Add("MDP-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox4.Checked) {
Try{
$job4 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zdlb_staging.bat} -Name "ZDL-B-DATA"
$listBox1.Items.Add("ZDLB-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox5.Checked) {
Try{
$job5 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zdls_staging.bat} -Name "ZDL-S-DATA"
$listBox1.Items.Add("ZDLS-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox6.Checked) {
Try{
$job6 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zub_staging.bat} -Name "ZUBOFI-DATA"
$listBox1.Items.Add("ZUBOFI-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox7.Checked) {
Try{
$job7 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\adp_staging_error.bat} -Name "ADP-ERR"
$listBox1.Items.Add("ADP-Error-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox8.Checked) {
Try{
$job8 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\kdp_staging_error.bat} -Name "KDP-ERR"
$listBox1.Items.Add("KDP-Error-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox9.Checked) {
Try{
$job9 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\mdp_staging_error.bat} -Name "MDP-ERR"
$listBox1.Items.Add("MDP-Error-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox10.Checked) {
Try{
$job10 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zdlb_staging_error.bat} -Name "ZDL-B-ERR"
$listBox1.Items.Add("ZDL-B-Error-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox11.Checked) {
Try{
$job11 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zdls_staging_error.bat} -Name "ZDL-S-ERR"
$listBox1.Items.Add("ZDL-S-Error-staging läuft...")
}catch [System.Exception]{}
}
if ($checkBox12.Checked) {
Try{
$job12 = start-jobhere { & C:\Users\mosermich\Desktop\Extractor\Ressources\zub_staging_error.bat} -Name "ZUBOFI-ERR"
$listBox1.Items.Add("ZUBOFI-Error-staging läuft...")
}catch [System.Exception]{}
}
if ($listBox1.Items.Count -eq 0) {
$listBox1.Items.Add("No-Data!")
}
Get-Job | Wait-Job | Where State -eq "Running"
$listBox1.Items.Add("All Jobs have been succesfully finished")
}else{}
Run Code Online (Sandbox Code Playgroud)