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 and files are processing one by one in loop and I want to update the progress bar according to the current count of the for loop.
Please suggest..
Asked
Active
Viewed 2.1k times
5

nitendra jain
- 433
- 4
- 8
- 16
-
update to the iterator in the loop. (if the loop is `for (int i = 0; i < 100; i++)` the iterator is i). – elyashiv Sep 27 '12 at 09:11
5 Answers
3
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.
3
Take a look at BackgroundWorker
class, particularly, at ProgressChanged
event.

Dennis
- 37,026
- 10
- 82
- 150
2
You should use BackgroundWorker combined with a ProgressBar control. Here is a simple example.

Yiğit Yener
- 5,796
- 1
- 23
- 26
0
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
}

Gayan Chinthaka Dharmarathna
- 391
- 5
- 21
-
1Please don't add the [same answer to multiple questions](http://meta.stackexchange.com/questions/104227/is-it-acceptable-to-ad??d-a-duplicate-answer-to-several-questions). Answer the best one and flag the rest as duplicates, once you earn enough reputation. If it is not a duplicate, tailor the post to the question – Manfred Radlwimmer Mar 24 '17 at 09:04
-
@ManfredRadlwimmer Sorry i am new here.thanks for the advice and i will follow in future. – Gayan Chinthaka Dharmarathna Mar 24 '17 at 09:09