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

  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();
        }
    }
} 

 

posted @ 2014-05-05 00:40  安静的灵魂冷冷清清  阅读(600)  评论(0编辑  收藏  举报