jaworekplay / Prototype

HCI Windows Forms
0 stars 0 forks source link

Progress bar #2

Open jaworekplay opened 11 years ago

jaworekplay commented 11 years ago

To enable progress bar to work we have to start new thread and start the worker in the manner as follows: private void DEACT_Load(object sender, System.EventArgs e) { // Start the BackgroundWorker. backgroundWorker1.RunWorkerAsync(); } and then private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { for (int i = 1; i <= 100; i++) { // Wait 100 milliseconds. Thread.Sleep(100); // Report progress. backgroundWorker1.ReportProgress(i); } } and after private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { // Change the value of the ProgressBar to the BackgroundWorker progress. progressBar1.Value = e.ProgressPercentage; // Set the text. this.Text = e.ProgressPercentage.ToString(); } This should be sufficient to provide asynchronous update. ;)

jaworekplay commented 11 years ago

Don't forget to include using System.Threading;