-
progressBar
In this forloop I am reading 3 files that takes about 20 seconds.
Now I have done a formula: (out / count) * 100 that will show progress.
So for the first file wich will be (1 / 3) * 100 wich will have a value of 33.33
the progressbar should be on 33.33 % but this is not happening ?
It waits until all 3 files is read and then display 100 % directly.
Any idéas why this is happening. 100 is the MaxValue for the progressBar1.
(If I just put a number like for example 30 instead the progressBar1 will fill up to 30 %.)
Code:
int count = 3;
for (int out = 1; out < (count + 1); out++)
{
this->progressBar1->Value = (out / count) * 100;
}
-
Change this seemed to solve the problem.
Code:
int out
to
double out
So the progressbar is working correctly now.
Another problem is occuring and that is on my Form I have a progressbar and a buttoncontrol.
When I press the button the progressbar is starting out with this for-loop.
Now if I press for example on the desktop with my cursor
wich make the form "unactive" the progressbar stops at the position it is and never starts again.
The whole form is "Not Responding" until the for-loop is ready.
What does this depend on. How can it be possible to update the progressbar/Form for each looping. I dont really know the reason to this ?
-
I have googled around and think that I have to activate the Form for each looping but are not sure that this is the approach.
The syntax I have seen is: Activated() but this is all I know if I am on the right track.
I have tried this inside the loop but this did not work:
Code:
this->Activate();
this->progressBar1->Value = (out / count) * 100;
-
Try putting a "Application.DoEvents();" inside your loop.
-
Assuming you're using .NET 2.0+, look into the BackgroundWorker component.
-
The "Application:: DoEvents();" for .NET 2008 worked for this.
Thanks.