This is a great example for a thread stop. Simple debugging trick for any looped process that needs the "e-brake" applied while making sure that the thread is working correctly. The idea is that you can manually stop a thread, to prevent that hanging sensation during any process. This works great with TCP and UDP protocol programs and ideal for all multi-threading programs.. feel free to implement as needed.
Simple Thread stop
'Simulated loop that will continue for ever,
'Kinda like a persistant thread that will not stop
Private Sub BackgroundProcess()
Dim i As Integer = 1
Do While True
ListBox1.Items.Add("Iterations: " + i)
i += 1
Loop
End Sub
'Thread created to handle the Background process
Dim t As Thread
t = New Thread(AddressOf Me.BackgroundProcess)
t.Start()
'add a button to the form to handle the "e-Brake" to the thread
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
t.Abort()
End Sub
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.