Task.Factory.StartNew多线程中将数值实时传递到UI显示

        private void button1_Click(object sender, EventArgs e)
        {
            Task t1 = Task.Factory.StartNew(() => k1());
            Task t2 = Task.Factory.StartNew(() => k2());
        }
 
        void k1()
        {
            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(100);
                this.Invoke(new Action(
                    () => { this.label1.Text = i.ToString(); }));
            }
        }
 
        void k2()
        {
            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(100);
                this.Invoke(new Action(
                    () => { this.label2.Text = i.ToString(); }));
            }
        }
原文地址:https://www.cnblogs.com/1955/p/10239356.html