How to update a progress bar at runtime using C #

I am using the code below to update the progress bar.

        ProgressBar.Visible = true; 
        ProgressBar.Minimum = 1; 
        ProgressBar.Maximum = PortCount; 
        ProgressBar.Value = 1; 
        ProgressBar.Step = 1; 

        int intdata = 5;
        for (int x = 1; x <= intdata; x++)
          {
            ProgressBar.PerformStep();
        }

        MessageBox.Show("Done");

But it is not updated at runtime. This is because the progress bar is on the same thread. If so, how to update this progress from another thread. Help...

+5
source share
2 answers

You do not specify a pump run time to update the control.

Although this is bad, you can do:

  • Call Refreshto control
  • Call Application.DoEvents
+6
source

Windows Forms? Refresh() ProgressBar . Application.DoEvents, , .

BackgroundWorker. ReportProgress. .

+6

All Articles