|
-
September 8th, 2009, 12:05 PM
#1
[RESOLVED]Interupting Do Until
I have the following code
Do Until [condition]
code
Loop
This loop takes sometimes up to a minute to execute. I would like to display a message box giving the user the option of terminating the loop. When I use ShowDialog the loop doesn't execute until DialogResult is returned. When I use Show, the forms buttons are not accessible until do loop is finished. How can I make this work?
Last edited by PaulJayKnight; September 13th, 2009 at 05:18 PM.
Reason: [RESOLVED]
-
September 8th, 2009, 02:43 PM
#2
Re: Interupting Do Until
What does the Loop do. If it is a processor intensive operation, I would recommend putting this on a separate thread. I am not sure which version of .NET you are using, but if it .NET 2.0 and above, there is a component called backgroundWorker component, that will help in achieving what you want. Check out MSDN, they have nice sample too that has the similar kind of code.
-
September 9th, 2009, 01:01 AM
#3
Re: Interupting Do Until
 Originally Posted by PaulJayKnight
I have the following code
Do Until [condition]
code
Loop
This loop takes sometimes up to a minute to execute. I would like to display a message box giving the user the option of terminating the loop. When I use ShowDialog the loop doesn't execute until DialogResult is returned. When I use Show, the forms buttons are not accessible until do loop is finished. How can I make this work?
I think you're using the wrong logic here What does this loop do, can you provide us with a small snippet ¿
-
September 9th, 2009, 01:15 AM
#4
Re: Interupting Do Until
 Originally Posted by PaulJayKnight
I have the following code
Do Until [condition]
code
Loop
This loop takes sometimes up to a minute to execute. I would like to display a message box giving the user the option of terminating the loop. When I use ShowDialog the loop doesn't execute until DialogResult is returned. When I use Show, the forms buttons are not accessible until do loop is finished. How can I make this work?
I am not a VB.NET guy so I can't say anything about how to implement this, but in Delphi I have done something similar. In the do until condition I include a check to see if a cancel variable has been set to true. Then every time in the loop I call something called ProcessMessages which allows events like button clicks to be handled. One of those buttons sets the cancel variable to true. So if the user presses the cancel button the loop stop incomplete. As to exact implementation I can't really help.
-
September 9th, 2009, 01:03 PM
#5
Re: Interupting Do Until
Wouldn't the ProcessMessages section of your code make the whole operation run slowly? The idea of multi-threading is what needs to be utilized in this case.
-
September 10th, 2009, 01:16 AM
#6
Re: Interupting Do Until
 Originally Posted by Shuja Ali
Wouldn't the ProcessMessages section of your code make the whole operation run slowly? The idea of multi-threading is what needs to be utilized in this case.
Considering that the wait is on the order of minutes, no (human) user will notice the millisecond check to see if there are pending events. If we were really so concerned with speed here, the bottleneck wouldn't be Application.ProcessMessages, but the rest of the code that is already a bottle neck. So while you could use multi-threading, to answer the original question
 Originally Posted by PaulJayKnight
I would like to display a message box giving the user the option of terminating the loop.
take a look at Application.DoEvents. From what I understand, it is equivalent to Application.ProcessMessages in Delphi.
-
September 10th, 2009, 01:30 PM
#7
Re: Interupting Do Until
 Originally Posted by jlund3
Considering that the wait is on the order of minutes, no (human) user will notice the millisecond check to see if there are pending events. If we were really so concerned with speed here, the bottleneck wouldn't be Application.ProcessMessages, but the rest of the code that is already a bottle neck. So while you could use multi-threading, to answer the original question take a look at Application.DoEvents. From what I understand, it is equivalent to Application.ProcessMessages in Delphi.
Well actually the DoEvents eats up the CPU. So it is not only about waiting, it is also about consuming the CPU when it is not required.
A good read is written in this blog
http://blogs.msdn.com/jfoscoding/arc...06/448560.aspx
-
September 12th, 2009, 10:00 AM
#8
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|