Solved

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

Posted on 2013-05-22
5
252 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 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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