I am processing some xml files in for loop and according to the number of files has been processed I want to show the progress bar. Suppose there are 100 files in directory
Take a look at BackgroundWorker class, particularly, at ProgressChanged event.
for(int i=1;i<linecount;i++)
{
progressBar1.Value = i * progressBar1.Maximum / linecount; //show process bar counts
LabelTotal.Text = i.ToString() + " of " + linecount; //show number of count in lable
int presentage = (i * 100) / linecount;
LabelPresentage.Text = presentage.ToString() + " %"; //show precentage in lable
Application.DoEvents(); keep form active in every loop
}
You should use BackgroundWorker combined with a ProgressBar control. Here is a simple example.
Process the 100 files using a Background Worker, call ReportProgress every iteration, hook on to the Process changed event of the backgroundworker and update a progressbar accordingly.
You can check out this tutorial for details.
Set Minimum and Maximum and then use the
Stepproperty with thePerformStepmethod to increment the value of the ProgressBar.
progressBar1.Step = 1;
int part=someList.Count / 100;
....
....
//Inside the loop
if (loop_counter % part == 0)
{
progressBar1.PerformStep();
}
See