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();
}
作者:SIR@君
Email:sirjun@foxmail.com
云购:注册立送五元红包,1元也能抢购IPhone啦!