C# winform 登陆等待中. [异步请求]BackgroundWorker组件的使用
时间:2011-05-26 来源:青瓷
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();
}