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循环后面的那些代码?

解决方案 »

  1.   

    System.Threading.Thread.Sleep(i);  等待i毫秒
      

  2.   

    是不是执行到System.Threading.Thread.Sleep(i);  这句,就跳出for循环,去执行for循环下面的功能语句呀 ?
      

  3.   


    不是,你的理解刚好相反,执行到System.Threading.Thread.Sleep(i)要等待i毫秒才去执行for循环下面的功能
      

  4.   

    就是线程阻塞!一般在多线程处理数据时有用
    System.Threading.Thread.Sleep(i); 就是阻塞i秒让这个线程不工作去处理其他线程,等i秒后线程恢复工作!
      

  5.   

    一开始我很奇怪的是,为什么不直接写个sleep(i),而非要System.Threading.Thread.Sleep(i); 写一大串。就像一个人去赶集卖东西,来到市场上,非要树立了个大牌子,写着:来自某某地的某某人来到某某卖某某。这么罗嗦一样。