如何在一个按钮中运行多个后台进程
本文关键字:按钮 运行 后台进程 一个 | 更新日期: 2023-09-27 17:57:58
我遇到了问题。我是 c# 的新手。在此代码中,当我单击 button2 时,它将仅运行bgutures.RunWorkerAsync();
。但是我需要修改它,例如如果我单击button2
,checkedListBox1.allitems
包含的所有项目都可以在 bgworker 中逐个下载。 任何人都可以帮忙吗?我的代码是:
private void button2_Click(object sender, EventArgs e)
{
button2.Enabled = false;
string DayAtoZ = " ";
string DayDead = " ";
string Dayutures = " ";
string Daysify = " ";
string Dayfx = " ";
if (checkedListBox1.SelectedItem == "")
{
}
else if (checkedListBox1.SelectedItem == Dayutures)
{
}
else if (checkedListBox1.SelectedItem == DayAtoZ)
{
}
else if (checkedListBox1.SelectedItem == Daysify)
{
}
else if (checkedListBox1.SelectedItem == DayDead)
{
}
else if (checkedListBox1.SelectedItem == Dayfx)
{
}
{
bgutures.RunWorkerAsync();
}
{
bgDead.RunWorkerAsync();
}
{
bgsify.RunWorkerAsync();
}
{
bgAtoZ.RunWorkerAsync();
}
{
}
}
而不是一个BackgoundWorker
根据需要使用尽可能多的。
if (checkedListBox1.SelectedItem == "")
{
var worker = new BackgroundWorker();
.. do setup
worker.RunWorkerAsync();
}
else if (checkedListBox1.SelectedItem == Dayutures)
{
var worker = new BackgroundWorker();
.. do setup
worker.RunWorkerAsync();
}