![]() ![]() | ||
You can stop a thread with the Abort method:
NewThread.Abort()
This brings a thread to a halt. Usually, it's far better to let the thread simply end (that is, return from the thread procedure) by itself, but if you really need to end a thread, you can do so with the Abort method.
We used the Abort method in the Threading example, as discussed in the In Depth section of this chapter; in that example, the user could stop a thread by clicking the "Cancel Counting" button, which executed the Abort method like this (you can see this example at work in Figure 24.10):
Dim Thread1 As New System.Threading.Thread(AddressOf counter1.Count) ⋮ Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click Thread1.Abort() End Sub
For more on how this example operates, take a look at the discussion in the In Depth section of this chapter.
![]() ![]() | ||