Solved

Stopping app in recursive loop?

Posted on 1998-01-30
5
137 Views
Last Modified: 2010-04-04
Can someone tell me how to stop an application when a recursive loop is running? For example, if I am recursively reading through an entire disk (which takes a long time), and I click the "Close" button, nothing happens.  I want to be able to stop everything and just shut down. I thought I had this figured out, but to no avail. :-)  
0
Comment
Question by:jexd99
5 Comments
 
LVL 4

Accepted Solution

by:
d003303 earned 50 total points
ID: 1358031
Yo,

define a global break-flag that is false initially. Set it to true in the OnCloseQuery-event of the form.
In your recursive loop, add the line Application.ProcessMessages and check for the break-flag. Exit the loop if the flag is true.

Slash/d003303
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1358032
You can do it with threads. -Look at the sorting example taht D3 or D2 has in the \demos\threads dir.
If you want to terminate a thread you just call the .Terminate method and that means taht your recursive proc will also terminate.

Good luck!
Matvey
0
 

Expert Comment

by:michael2010898
ID: 1358033
If the program responds to the button click you
can use application.terminate
If not then use thread for the procedure and when the user
clicks the button use .Terminate if you want to stop
the procedure or use .Supend to supend it and then you will be
able to continue it with .Resume.


0
 
LVL 4

Expert Comment

by:d003303
ID: 1358034
Threads might be a better solution than mine. You could also recurse through several disks the same time, just start a second instance of the thread object. Like Matvey said, the sorting example is worth a look.
If want to use threads, don't hesitate to reject my answer.

Slash/d003303
0
 

Author Comment

by:jexd99
ID: 1358035
Thanks for the info. :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

11 Experts available now in Live!

Get 1:1 Help Now