Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在一个按钮中运行多个后台进程_C#_Backgroundworker - Fatal编程技术网

C# 如何在一个按钮中运行多个后台进程

C# 如何在一个按钮中运行多个后台进程,c#,backgroundworker,C#,Backgroundworker,我有个问题。我是新来的。在这段代码中,当我单击按钮2时,它将运行bgutures.RunWorkerAsync()仅限。但是我需要修改它,比如如果我点击按钮2,那么检查列表框1.allitems包含的所有项目都将在bgworker中逐个下载。有谁能帮忙吗。 我的代码是: private void button2_Click(object sender, EventArgs e) { button2.Enabled = false; string Da

我有个问题。我是新来的。在这段代码中,当我单击按钮2时,它将运行
bgutures.RunWorkerAsync()仅限。但是我需要修改它,比如如果我点击
按钮2
,那么
检查列表框1.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();
    }

您好,先生..设置意味着,我需要在这里修改什么,请在我的代码中添加我需要的内容。因为我是c#的新手,这不起作用,你能不能改变这个,或者添加mycode,