標籤:style blog io ar color os sp div on
進度條賦值
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 = value;11 this.label1.Text = "初始化中 :" + value.ToString() + "%";12 if (value == 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#進度條