多线程调用主线程控件

private void button3_Click(object sender, EventArgs e)
        {
            this.label1.Text = "123kkk";
            //System.Threading.Thread.Sleep(0);
            
            
            MessageBox.Show(this.timer1.Enabled.ToString());

            var th = new System.Threading.Thread(ThreadStart);
            th.Start();
        }

        public void ThreadStart()
        {
            //for (int i = 0; i < 501000; i++)
                //this.Controls["label1"].Text = "123456";
            //textBox1.BeginInvoke(new Action(() => { textBox1.Text = "hello"; }));
            //for (int i = 0; i < 501000; i++)
                label1.BeginInvoke(new Action(() => { label1.Text = "hello"; }));
                label2.BeginInvoke(new Action(() => { label2.Text = ra.Next(1000).ToString(); }));
        }

  

posted @ 2016-08-03 10:52  彭成刚  阅读(532)  评论(0编辑  收藏  举报