在做某个比较耗时间的操作,如某个操作(进程):ClearDiary()时,
我想用进度条显示该进程运行完成百分比,请问如何做?

解决方案 »

  1.   

             private void button1_Click(object sender, System.EventArgs e)
    {
    Thread t = new Thread(new ThreadStart(SetProgress));
    t.Start();
    for (int i = 0;i<4;i++)
    {
    MessageBox.Show(i.ToString());
    }
    t.Join();
    } public  void SetProgress()
    {
    timer1.Start();;
    }                  int step =1;
    private void timer1_Tick(object sender, System.EventArgs e)
    {
    if(progressBar.Position == 100) step = -1;
    else if (progressBar.Position == 0) step = 1; 
    progressBar.Increment(step);
    }为何点击Button时,MessageBox.Show(i.ToString())不与t.Start()并行呢?也就是为什么不一起进行progressBar的进度改变跟MessageBox.Show(i.ToString())呢?
    请各位给我一些提示。/。
      

  2.   

    可以用delegate把Progress.PerformStep()传到工作进程中,在ClearDiary()中调用这个delegate
      

  3.   

    在button1_Click退出之前消息队列中的消息是不会被处理的
      

  4.   

    把t.Join去掉应该就可以一起运行了
      

  5.   

    timer1_Tick能被调用吗?
    timer在多线程环境中不是很好用
      

  6.   

    不能被调用
    那我不用timer试试看,
    fancyf(凡瑞)非常感谢。
      

  7.   

    线程的问题,,不大了解,顶了。to subjectForm(关于窗体关闭的问题) :
    不用timer你如何实现?
      

  8.   

    我是首先考虑用Thread.Sleep来延时、时间间隔的