Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 16044

VS 2010 Pause and/or stop code inside a loop with a button click

$
0
0
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! :)

Viewing all articles
Browse latest Browse all 16044

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>