Jump to content
  • Advertisement
Sign in to follow this  
coolblue

[.net] Exit loop

This topic is 3755 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

I have a simulation running in a winforms gdi+ application. I have a while loop and it can theoretically fun forever. In need to be able to exit this loop if the user presses a certain key (ie "p"). The keypress event does not work and neither does the processCmdKey method as they will not fire until the loop has finished. How do I exit this loop with a keypress.

Share this post


Link to post
Share on other sites
Advertisement
Make a call to to...

Application.DoEvents();

in your loop. It will force the application to process the message loop and fire your keyboard event.

Share this post


Link to post
Share on other sites
Alternatively, it might be more sensible to run this task in a background thread. There are numerous ways of doing this - probably the tidiest from a WinForms point of view is to use the BackgroundWorker component.

Making your app multithreaded will retain a responsive UI, and it can take better advantage of the increasingly popular multiple core CPUs.

Share this post


Link to post
Share on other sites
Quote:
Original post by benryves
Alternatively, it might be more sensible to run this task in a background thread. There are numerous ways of doing this - probably the tidiest from a WinForms point of view is to use the BackgroundWorker component.

Making your app multithreaded will retain a responsive UI, and it can take better advantage of the increasingly popular multiple core CPUs.
This is the way that's generally recommended in best-practices documents, IIRC.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!