C# winform 登陆等待中. [异步请求]BackgroundWorker组件的使用

 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            int result = 0;
            for (int i = 0; i < 100000; i++)
            {
                result += i;
            }
            System.Threading.Thread.Sleep(3000);
            e.Result = result;


        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {

        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            label1.Text =e.Result.ToString();
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "正在登陆中.....";
            button1.Enabled = false;

            backgroundWorker1.RunWorkerAsync();
          
        }

posted @ 2011-05-26 16:13  Sir。  阅读(1795)  评论(1编辑  收藏  举报