|
Answer» YAY ! Got this done allready
Found this on internet:
Code: [Select]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 Sub End Class
everythink its working now thanks for helping lol, that's the method I just described lol, didnt know you are talking about that well, it uses a form-level variable to flag when the thread should end. that was what I meant.
good to hear you got it workin.
what is this for? Just curious.Its should be a metronome, that used when you play guitar
|