also if you need to break out of a loop you can maybe use a global variable that is checked every loop and the button will just need to set the variable to something like stoploop=true
Main Topics
Browse All TopicsI have a C# program where user clicks a button and begins executing a "for" loop that does some processing based on user input. I would like the user to be able to click a button on the same form to be able to interrupt the processing. Since the processing is in a "for" loop when I click the button and never received a click event. Is there a way I can execute the "for" loop and be able to click a button on the form that interrupts that "for" loop.
Any sage words of advice would be appreciated.
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
It can be done quite a bit simpler. Forms are by default multi threaded, they have to be, because the Win32 messages are send and processed asynchronously. You can use that information to create a very simple loop that does not involve extra multi threading to succeed and is still very responsive when the user clicks the Cancel button.
Place a button "btnCancel" and a button "btnProcessLoop" on your form and doubleclick the Click events in the properties window and paste the following code in it. You may add a small textbox with the name txtResults to see the loop running.
Business Accounts
Answer for Membership
by: elpamyelhsaPosted on 2009-08-08 at 05:59:53ID: 25049609
you might have to execute the loop in a separate thread to keep the form responding
om/UploadF ile/mgold/ Multithrea dingIntro1 0062005000 439AM/Mult ithreading Intro.aspx ? ArticleID =920ecafc- e83b-4a9c- a64d-0b39a d885705
http://www.c-sharpcorner.c
hope this helps