for(int i = 1; i <= 50; i++)
{
ThePerc = i / 50 * 100;
ProgE->Value = ThePerc;
Thread::Sleep(5000);
}
[.net] Progress Bar
Sorry to ask another, but this has been troubling me and nothing on google helps, here is essentially the code:
It would 'seem' to work fine, but what is does is instead of incrementing as it goes, it 'stays at 0%' untill it is completly finished and jumps to 100%, there is no incremention. Am I doing this all wrong or is it my computer? Also, it runs when a button is clicked if that matters.
p.s. I tried using PreformStep(), same thing.
I'm guessing that maybe ThePerc is an int?
If it's not then you might to do some casting trickery such as
ThePerc = ((float)i) / 50 * 100;
An int divided by any number will always evaluate to an int unless told otherwise.
If it's not then you might to do some casting trickery such as
ThePerc = ((float)i) / 50 * 100;
An int divided by any number will always evaluate to an int unless told otherwise.
If this code is being executed in the same thread as your form/control's message loop, then your app never has a chance to repaint itself before the code is done executing. I'd suggest using a separate thread to run the code in, spawning a new one if necessary.
Quote:Original post by TheBluMage
If this code is being executed in the same thread as your form/control's message loop, then your app never has a chance to repaint itself before the code is done executing. I'd suggest using a separate thread to run the code in, spawning a new one if necessary.
Use a timer rather than a separate thread. All a thread gives you is resource overhead and the pain to synchronize back to the ui thread.
Or, to stay with the current code, add a call to Application::DoEvents before the sleep.
Quote:Original post by Anonymous PosterQuote:Original post by TheBluMage
If this code is being executed in the same thread as your form/control's message loop, then your app never has a chance to repaint itself before the code is done executing. I'd suggest using a separate thread to run the code in, spawning a new one if necessary.
Use a timer rather than a separate thread. All a thread gives you is resource overhead and the pain to synchronize back to the ui thread.
Or, to stay with the current code, add a call to Application::DoEvents before the sleep.
Or for the control only, Control.Update [smile]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement