In VB6 the DoEvents would allow the loop to pause so other things could happen.
In VB.Net the rules have changed and I can't figure out how to get the code to
pause execution inside a loop.
I am trying to get the code to pause and/or stop inside the loop when a button is pressed.
This requires two things on a form:
A button named btnPauseStop
A label named lblCountDown
- - - - - - - - - - - - - -
Option Strict On
Option Explicit On
Imports System.Threading 'Thread.sleep(1000) = 1 second
Public Class Form1
Dim i As Integer
Private Sub btnPauseStop_Click(sender As System.Object, e As System.EventArgs) Handles btnPauseStop.Click
Call PauseStopLoop()
End Sub
Public Sub PauseStopLoop()
i = 0
While i < 500
lblCountDown.Text = CStr(i)
i = i + 1
Thread.Sleep(300) 'the larger this number the slower the loop executes...
Me.Refresh()
End While
End Sub
End Class
Thanks in advance! :)
In VB.Net the rules have changed and I can't figure out how to get the code to
pause execution inside a loop.
I am trying to get the code to pause and/or stop inside the loop when a button is pressed.
This requires two things on a form:
A button named btnPauseStop
A label named lblCountDown
- - - - - - - - - - - - - -
Option Strict On
Option Explicit On
Imports System.Threading 'Thread.sleep(1000) = 1 second
Public Class Form1
Dim i As Integer
Private Sub btnPauseStop_Click(sender As System.Object, e As System.EventArgs) Handles btnPauseStop.Click
Call PauseStopLoop()
End Sub
Public Sub PauseStopLoop()
i = 0
While i < 500
lblCountDown.Text = CStr(i)
i = i + 1
Thread.Sleep(300) 'the larger this number the slower the loop executes...
Me.Refresh()
End While
End Sub
End Class
Thanks in advance! :)