I am using a progressbar in .NET to show progress for an operation.
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 %.)

int count = 3;

for (int out = 1; out < (count + 1); out++)
	{ 
	        this->progressBar1->Value = (out / count) * 100;
        }

changing
int out to double out
seemed to solve the problem.

The progressbar is working correctly with this code:

int count = 3;

for (double out = 1; out < (count + 1); out++)
	{ 
	        this->progressBar1->Value = (out / count) * 100;
        }

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 will make the form "unactive" as any other application on the computer, the progressbar stops at the position it is and never starts again.
The whole form is "Not Responding" until the for-loop is ready/finished.

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.

// ..
{ 
   this->progressBar1->Value = (out / count) * 100;
   this->progressBar1->Invalidate() ;
   this->progressBar1->Update() ; // if immediate repaint is required
}
// ..
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.