2003用多线程, 2005有一个自带的多线程Progressbar

解决方案 »

  1.   

    private Thread myThread;
            private void Form1_Load(object sender, EventArgs e)
            {
                myThread = new Thread(new ThreadStart(RunsOnWorkerThread));
                myThread.Start();
            }        private void RunsOnWorkerThread()
            {
                for (int i = 0; i < 100; i++)
                {
                    ShowProgress(Convert.ToString(i) + "%", i);
                    Thread.Sleep(100);
                }
            }        public void ShowProgress(string msg, int percentDone)
            {
                System.EventArgs e = new MyProgressEvents(msg, percentDone);
                object[] pList = { this, e };
                BeginInvoke(new MyProgressEventsHandler(UpdateUI), pList);        }        private delegate void MyProgressEventsHandler(object sender, MyProgressEvents e);        private void UpdateUI(object sender, MyProgressEvents e)
            {            label1.Text = e.Msg;            progressBar1.Value = e.PercentDone;        }
            public class MyProgressEvents : EventArgs
            {            public string Msg;            public int PercentDone;            public MyProgressEvents(string msg, int per)
                {                Msg = msg;                PercentDone = per;            }        }
      

  2.   

    Application.DoEvents();
    刷新显示
      

  3.   

    ProgressDialog: for executing long-running code with some thread safety - The Code Project - C# Programming
    http://www.codeproject.com/csharp/PIEBALDProgressDialog.asp