My title may make my question sound confusing, but it is not.
I have a list of tasks to do and a ProgressBar. When I loop through the list of tasks, I want to display the progress through a ProgressBar:
double percentage;
for(int i = 0; i < tasks.Count; i++)
{
percentage = (double)i + 1 / (double)tasks.Count;
this.Invoke((MethodInvoker)delegate
{
progressBar1.Value = (int)Math.Round(percentage * 100);
});
// Do tasks here...
}
So if I have say, 20 tasks I want progressBar1 to have the value of 5 ((1 / 20) * 100), then when it loops through again it has the value of 10, 15 and so on. The method that I am using right now does not work properly, on the first task progressBar1 has a value of 0, then when it loops through again it has the value of 100. Is there a way of doing what I am trying to achieve?
Thanks.
1 Answer