我用的是时间控件来判断的,
backgroundWorker里面写你的代码
在 backgroundWorker_RunWorkerCompleted事件里面
结束时间控件的运行
private void timer_Tick(object sender, EventArgs e)
{
BarRoll();
} delegate void CurrentBarRoll();
private void BarRoll()
{
if (this.InvokeRequired)
{
CurrentBarRoll currentBarRoll = new CurrentBarRoll(BarRoll);
this.Invoke(currentBarRoll, new object[] { });
}
else
{
progressBar.PerformStep();
if (progressBar.Value == progressBar.Maximum)
{
progressBar.Value = progressBar.Minimum;
}
}
}
backgroundWorker里面写你的代码
在 backgroundWorker_RunWorkerCompleted事件里面
结束时间控件的运行
private void timer_Tick(object sender, EventArgs e)
{
BarRoll();
} delegate void CurrentBarRoll();
private void BarRoll()
{
if (this.InvokeRequired)
{
CurrentBarRoll currentBarRoll = new CurrentBarRoll(BarRoll);
this.Invoke(currentBarRoll, new object[] { });
}
else
{
progressBar.PerformStep();
if (progressBar.Value == progressBar.Maximum)
{
progressBar.Value = progressBar.Minimum;
}
}
}
http://msdn.microsoft.com/zh-cn/library/system.componentmodel.backgroundworker.aspx
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
//做你费时的操作
UpdatePlanInfo();//更新进度
}//更新进度的委托
delegate void DelegateUpdatePlan(); //更新进度
private void UpdatePlanInfo()
{
if (this.InvokeRequired)
{
DelegateUpdatePlan delegateUpdateItem = new DelegateUpdatePlan(UpdatePlanInfo);
this.Invoke(delegateUpdateItem);
}
else
{
progressBar.PerformStep();
}
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
for(int i =0;i<100;i++)
{
UpdatePlanInfo();//更新进度
}
}
嘿嘿~~
dgvResult.DataSource = MyClass.Search(searchType, txtSearch.Text.Trim());
这句话要操作很多数据,所以很费时。