backgroundworder 简单使用

//手动创建backgroundworker组件



///创建

private backgroundworker bgd = new backgroundworker();

///声明xmldoment

private xmldoment doment = null;

/// Load 加载事件

private void Form1_Load(object sender , EventArgs e)

{

/// 执行操作

this.bgd.DoWorker +=delegate(object obj,DoWorkerEventArgs dwe)

{

doment = new xmldoment();

doment.Load(@"地址.xml");

};

///执行完成后

this.bgd.RunWorkerCompleted +=delegate(object obj,RunWorkerCompletedEventArgs es)

{

if(doment!=null)

{Messagebox.show(doment.InnerXml,"Dowload Complete"}

else

messagebox.show("失败");

};



}



private void ButRun(object sender , EventArgs e)

{

this.bgd.RunWorkerAsync();//开始执行

this.ButRun.Enabled = false;

while(this.bgd.IsBusy)

{

Application.DoEvents();

}

this.ButRun.Enabled = true;

}

你可能感兴趣的:(background)