Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
Computer Hope forum e-mail issues and down time
0 Members and 1 Guest are viewing this topic.
Public Class Form1 Dim accessLock As New Object Dim endThread As Boolean = False Dim PlayThread As New System.Threading.Thread(AddressOf CodeInThread) Private Sub CodeInThread() Dim keepRunning As Boolean = True While keepRunning 'keeps thread running forever 'We lock, because that is one way of ensuring that no other thread 'is accessing the same variables at the same time SyncLock accessLock If endThread Then keepRunning = False End If End SyncLock End While 'loop forever until keepRunning = False 'keepRunning now equals false 'put cleanup code here 'when the sub finishes, the thread ends End Sub Public Sub StopThread() SyncLock accessLock endThread = True End SyncLock End Sub Private Sub StopBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopBtn.Click StopThread() End Sub Private Sub StartBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartBtn.Click PlayThread.Start() End SubEnd Class