LEO's DotNET Blog

技术 业务 = 企业应用软件

博客园 首页 新随笔 联系 订阅 管理

BackgroundWorker是vs2005自带的,以下代码实现异步修改TextBox的Text

 1 private void button2_Click(object sender, EventArgs e)
 2        {
 3            this.textBox1.Text = "start";
 4
 5            this.backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
 6            this.backgroundWorker1.RunWorkerAsync();            
 7        }
      
 8
 9        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
10        {
11            for (int i = 0; i < 3; i++)
12            {
13                for (int j = 0; j < 100000000; j++)
14                {
15                    j++;
16                    j--;
17                }

18                this.textBox1.Text = i.ToString();
19            }

20        }

21
22        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
23        {
24            this.textBox1.Text = "complete";
25        }


 

posted on 2008-02-14 11:39  !LEO  阅读(643)  评论(2编辑  收藏  举报