我想要的效果是让进度条和下面5句代码同时执行并同时显示效果。但每次都是执行完 5句代码 后才显示出进度条,这样进度条就失去了意义,因为 5句代码 执行完了所有的事就已经完成了,进度条才出来简直是浪费时间,就没有意义了。请教高手指点,谢谢。全部的代码我也都抟出来了。5句代码是:            super.aveeragePrice(super.AllUrl1, ref averagePrice1, super.txtLookPrice1, ref table1);
            super.aveeragePrice(super.AllUrl2, ref averagePrice2, super.txtLookPrice2, ref table2);
            super.aveeragePrice(super.AllUrl3, ref averagePrice3, super.txtLookPrice3, ref table3);
            super.aveeragePrice(super.AllUrl4, ref averagePrice4, super.txtLookPrice4, ref table4);
            super.aveeragePrice(super.AllUrl5, ref averagePrice5, super.txtLookPrice5, ref table5);进度条窗口全部的代码:    public partial class Loading : Form
    {
        int i;
        public Loading()
        {
            InitializeComponent();
        }        DataTable table1;
        DataTable table2;
        DataTable table3;
        DataTable table4;
        DataTable table5;
        double averagePrice1;
        double averagePrice2;
        double averagePrice3;
        double averagePrice4;
        double averagePrice5;
        超市 super;
        public Loading(超市 super, ref DataTable table1, ref DataTable table2, ref DataTable table3, ref DataTable table4, ref DataTable table5, ref double averagePrice1, ref double averagePrice2, ref double averagePrice3, ref double averagePrice4, ref double averagePrice5)
            : this()
        {
            this.super = super;
            this.table1 = table1;
            this.table2 = table2;
            this.table3 = table3;
            this.table4 = table4;
            this.table5 = table5;
            this.averagePrice1 = averagePrice1;
            this.averagePrice2 = averagePrice2;
            this.averagePrice3 = averagePrice3;
            this.averagePrice4 = averagePrice4;
            this.averagePrice5 = averagePrice5;            timer1.Interval = 100;
            timer1.Enabled = true;            super.aveeragePrice(super.AllUrl1, ref averagePrice1, super.txtLookPrice1, ref table1);
            super.aveeragePrice(super.AllUrl2, ref averagePrice2, super.txtLookPrice2, ref table2);
            super.aveeragePrice(super.AllUrl3, ref averagePrice3, super.txtLookPrice3, ref table3);
            super.aveeragePrice(super.AllUrl4, ref averagePrice4, super.txtLookPrice4, ref table4);
            super.aveeragePrice(super.AllUrl5, ref averagePrice5, super.txtLookPrice5, ref table5);
        }        private void timer1_Tick(object sender, EventArgs e)
        {
            progressBar1.Minimum = 1;
            progressBar1.Maximum = 1;            i++;
            progressBar1.Value = i;
            if (i == progressBar1.Maximum)
            {
                timer1.Enabled = false;
                this.Close();
            }
        }
    }

解决方案 »

  1.   

    progressBar1.Maximum = 5;
    super.aveeragePrice(super.AllUrl1, ref averagePrice1, super.txtLookPrice1, ref table1);
    progressBar1.Value=progressBar1.Value-1;
    super.aveeragePrice(super.AllUrl2, ref averagePrice2, super.txtLookPrice2, ref table2);
    progressBar1.Value=progressBar1.Value-1;
    super.aveeragePrice(super.AllUrl3, ref averagePrice3, super.txtLookPrice3, ref table3);
    progressBar1.Value=progressBar1.Value-1;
    super.aveeragePrice(super.AllUrl4, ref averagePrice4, super.txtLookPrice4, ref table4);
    progressBar1.Value=progressBar1.Value-1;
    super.aveeragePrice(super.AllUrl5, ref averagePrice5, super.txtLookPrice5, ref table5);
    progressBar1.Value=0;
    不太会用progressBar1将就看下
      

  2.   

    创建委托delegate来执行progressBar1.Value=progressBar1.Value-1;