C#中跨线程的调用的方法--this.invoke

时间:2014-05-09 19:00:19   收藏:0   阅读:560
bubuko.com,布布扣
  private void button1_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(display));
            thread.Start();
        }
 
        private void display()
        {
            while (true)
            {
                 Thread.Sleep(100);
                 this.Invoke(new threadcall(SetText2));
            }
         }
 
        int count = 0;
 
        public delegate void threadcall();
 
        //threadcall Set = ;
 
        private void SetText2()
        {
            count++;
            this.label1.Text = count.ToString();
        }
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Dispose();
            //thread.Abort();
        }
    }
} 
bubuko.com,布布扣

 

C#中跨线程的调用的方法--this.invoke,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!