Loop Kills Application?

  • Thread starter Thread starter Jason Molt
  • Start date Start date
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
 
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
 
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?
 
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
 
Back
Top