Jump to content
  • Advertisement
Sign in to follow this  
Satan666

[.net] Progress Bar

This topic is 4892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry to ask another, but this has been troubling me and nothing on google helps, here is essentially the code:
for(int i = 1; i <= 50; i++) 
{
ThePerc = i / 50 * 100;
ProgE->Value = ThePerc;
Thread::Sleep(5000);
}



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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
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.


Or for the control only, Control.Update [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by Kristafarii
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.


Worked, thanks again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!