Loop Kills Application?

J

Jason Molt

Do until bStop = False
'there's some code here
'etc, etc
Loop
'some more code here

And then, I have a button that sets bStop = False when clicked: the program
blows up, fatal exception. What the...?

// fark0
 
N

Number 11950 - GPEMC! Replace number with 11950

Jason Molt said:
Do until bStop = False
'there's some code here
'etc, etc
Loop
'some more code here

And then, I have a button that sets bStop = False when clicked: the program
blows up, fatal exception. What the...?

// fark0

Is there a DoEvents or equivalent instruction for easing the breakage of
loops? Also, if you substitute While Wend for your Do Until Loop can you
achieve the same result with your code???

TIA
 
M

Mr. Arnold

Jason Molt said:
Do until bStop = False
'there's some code here
'etc, etc
Loop
'some more code here

And then, I have a button that sets bStop = False when clicked: the
program blows up, fatal exception. What the...?


Fatal exception as far as what? What is the rest of the error message?
 
G

Guest

well this runs as expected

Dim bstop As Boolean = True
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim icount As Integer
Do Until bstop = False
'there's some code here
'etc, etc
Debug.WriteLine(icount.ToString)
Application.DoEvents()
icount += 1
Loop
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
bstop = False
End Sub


so the problem is probably in the part where there is some code :)

you need doevents in this case to let the thread check the state of the
boolean
otherwise you would have an endless loop wich might also depending on the
code that is in the loop result in out of memory ( out of stack ) exceptions
or other unpredictable results :)

regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top