Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now