1 //载入滚动图,在主线程里开启一个子线程,子线程执行完毕再回到主线程 2 private void loadThread() 3 { 4 circularProgress.Visible = true; 5 circularProgress.IsRunning = true; 6 Thread threadProcess = new Thread(new ParameterizedThreadStart(funtion)); 7 threadProcess.Start(); 8 } 9 10 private void funtion(object o) 11 { 12 for (int i = 1; i < 1000; i++) 13 { 14 Console.WriteLine(i); 15 } 16 17 if (base.InvokeRequired) 18 { 19 base.Invoke(new Action(() => 20 { 21 circularProgress.IsRunning = false; 22 circularProgress.Visible = false; 23 })); 24 }
1 //用委托 2 // 定义一个委托实现回调函数 3 public delegate void CallBackDelegate(); 4 CallBackDelegate callBackDelegate; 5 private void loadThread() 6 { 7 circularProgress.Visible = true; 8 circularProgress.IsRunning = true; 9 callBackDelegate = new CallBackDelegate(stopCircularProgress); 10 Thread threadProcess = new Thread(new ParameterizedThreadStart(funtion)); 11 threadProcess.Start(); 12 } 13 14 private void funtion(object o) 15 { 16 for (int i = 1; i < 1000; i++) 17 { 18 Console.WriteLine(i); 19 } 20 this.Invoke(callBackDelegate); 21 } 22 23 private void stopCircularProgress() 24 { 25 circularProgress.IsRunning = false; 26 circularProgress.Visible = false; 27 }