异步函数调用与实现

写了个小DEMO

    private void button1_Click(object sender, EventArgs e)
        {

            Task.Run(() =>
            {

                for (int i = 0; i < 100; i++)
                {
                    Invoke(new Action(() => { textBox1.Text = i.ToString(); }));
                    Thread.Sleep(10);
                }

            });
            MessageBox.Show("ok");
        }
   private async void button1_Click(object sender, EventArgs e)
        {

            await Task.Run(() =>
            {

                for (int i = 0; i < 100; i++)
                {
                    Invoke(new Action(() => { textBox1.Text = i.ToString(); }));
                    Thread.Sleep(10);
                }

            });
            MessageBox.Show("ok");
        }

猜你喜欢

转载自blog.csdn.net/neo9781467/article/details/85621381