Sign in to follow this  
coolblue

[.net] Exit loop

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this