Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-05-22
5
Medium Priority
?
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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 86

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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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