首页 > 代码库 > C#进度条

C#进度条

进度条赋值

 1         public void SetProgressValue(int value) 2         { 3             if (this.InvokeRequired) 4             { 5                 Action<Int32> stepHandle = new Action<int>(SetProgressValue); 6                 this.Invoke(stepHandle, new object[] { value }); 7             } 8             else 9             {10                 this.progressBarOfCreateDatabase.Value =http://www.mamicode.com/ value;11                 this.label1.Text = "初始化中 :" + value.ToString() + "%";12                 if (value =http://www.mamicode.com/= this.progressBarOfCreateDatabase.Maximum) this.Close();13             }14         }

耗时操作

 1         void ThreadStartCallback() 2         { 3             Action createCallback = SDYF.TCRC.Bussiness.Commander.CreateDB;//耗时操作 4             IAsyncResult asyncResult = createCallback.BeginInvoke(null, null); 5             Int32 i = 0; 6             while (!asyncResult.IsCompleted) 7             { 8                 if (i < 99) 9                 {10                     i++;11                 }12                 Thread.Sleep(40);13                 SetProgressValue(i);14             }15             SetProgressValue(100);16         }

开启线程

1         private void CreateDatabase_Load(object sender, EventArgs e)2         {3             new System.Threading.Thread(new System.Threading.ThreadStart(ThreadStartCallback)).Start();4         }

 

C#进度条