backgroundWorker 等待窗口的实现(loading窗口)

 

用模对话框显示窗口,后台执行文件的列出。。。方法如下

 

public void chang()
{
try
{
Form loadingform
= new loading();
loadingform.StartPosition
= FormStartPosition.CenterParent;
loadingform.ShowDialog();
}
catch
{

}
}

private void ultraButton1_Click(object sender, EventArgs e)
{

backgroundWorker1.RunWorkerAsync();
//开始后台执行

chang();
//调用等待窗口

backgroundWorker1.CancelAsync();
//停止后台执行

ultraButton1.Enabled
= true;

}


private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
FindFile(
@"C:\Users\王彬\Documents\"); //后台执行列出此目录下所有文件
}

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{

}

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Application.OpenForms[
"loadingform"].Close(); //关闭等待窗口
}

 

posted @ 2010-05-08 16:57  wangbin5542  阅读(1016)  评论(0编辑  收藏  举报