Solved

Cancel - a executing for next loop if a button is clicked

Posted on 2013-05-22
5
248 Views
Last Modified: 2013-05-22
In my windows form based application I have a for each loop.  I want the application to do it stuff in the for next loop until it is done OR the user clicks on the cancel button.  How would i make it recognise that the cancel button has been clicked while the for loop buttons is executing in another procedure??
0
Comment
Question by:vbnetcoder
  • 3
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39188660
You toggle a form level boolean in the cancel button handler.

In the loop, check the flag.  You must add DoEvents() inside the loop to allow the cancel button click to be processed.

*A more robust approach would be to place the work into a background thread with the BackgroundWorker() control.
0
 

Author Comment

by:vbnetcoder
ID: 39188688
It tells me that DoEvents is not declared
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39188692
Sorry...for VB.Net you'd use "Application.DoEvents()".
0
 

Author Comment

by:vbnetcoder
ID: 39188700
That works thanks much!
0
 

Author Closing Comment

by:vbnetcoder
ID: 39188801
ty
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question