private void function1()
{ this.progressBar3.Maximum = this.GetRecordCounts();
for (int i = 0; i <= this.GetRecordCounts(); i++)
{
this.progressBar3.Value = i;
Application.DoEvents();
//
double percent = 100 * (this.progressBar3.Value - this.progressBar3.Minimum) / (this.progressBar3.Maximum - this.progressBar3.Minimum);
this.label6.Text = "正在导出..." + percent.ToString() + "%";
label6.Update();
System.Threading.Thread.Sleep(i);
}//后面需要执行的一些工作代码
......
}
由于本人刚学c#不到2周,这句System.Threading.Thread.Sleep(i);的意思是不是当执行到此语句的时候,跳出for循环,去执行for循环后面的那些代码?
{ this.progressBar3.Maximum = this.GetRecordCounts();
for (int i = 0; i <= this.GetRecordCounts(); i++)
{
this.progressBar3.Value = i;
Application.DoEvents();
//
double percent = 100 * (this.progressBar3.Value - this.progressBar3.Minimum) / (this.progressBar3.Maximum - this.progressBar3.Minimum);
this.label6.Text = "正在导出..." + percent.ToString() + "%";
label6.Update();
System.Threading.Thread.Sleep(i);
}//后面需要执行的一些工作代码
......
}
由于本人刚学c#不到2周,这句System.Threading.Thread.Sleep(i);的意思是不是当执行到此语句的时候,跳出for循环,去执行for循环后面的那些代码?
不是,你的理解刚好相反,执行到System.Threading.Thread.Sleep(i)要等待i毫秒才去执行for循环下面的功能
System.Threading.Thread.Sleep(i); 就是阻塞i秒让这个线程不工作去处理其他线程,等i秒后线程恢复工作!