private void btnStart_Click(object sender, EventArgs e) { if (isProcessRunning) { MessageBox.Show("A process is already running."); return; } Thread backgroundThread = new Thread( new ThreadStart(() => { isProcessRunning = true; //progressBar1 Starts here for (int n = 0; n < 100; n++) { Thread.Sleep(50); progressBar1.BeginInvoke(new Action(() => progressBar1.Value = n)); } MessageBox.Show("Thread completed!"); if (progressBar1.InvokeRequired) progressBar1.BeginInvoke(new Action(() => progressBar1.Value = 0)); //progressBar1 Starts here for (int m = 0; m < 100; m++) { Thread.Sleep(50); progressBar2.BeginInvoke(new Action(() => progressBar2.Value = m)); } MessageBox.Show("Thread completed!"); if (progressBar2.InvokeRequired) progressBar2.BeginInvoke(new Action(() => progressBar2.Value = 0)); isProcessRunning = false; } )); backgroundThread.Start(); }
progressBar2.BeginInvoke(new Action(() => progressBar2.Value = n));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)