运行任务代码时阻止ui?

时间:2018-08-11 11:09:15

标签: c#

当我运行代码时,此代码 ui表单块有什么问题。ui表单块

private  void button2_Click(object sender, EventArgs e)
{
    Task t1 = new Task( check2);
    Task t2 = new Task( check2);
    t1.Start();
    t2.Start();
}

private  void check2()
{           
    for (int  a=0 ; a <= 100000; a++)
    {
        this.Invoke(new Action(() =>
        {
            listBox2.Items.Add(a);
        }
     }                       
}

0 个答案:

没有答案