JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Starting Threads

To start a thread, you can use the thread's Start method:


This makes the thread begin executing the code in the thread procedure you passed to its constructor (see the previous topic). Here's how we used the Start method in the Threading example on the CD-ROM, as discussed in the In Depth section of this chapter (you can see this example at work in Figure 24.10):

    Dim counter1 As New counter()
    Dim Thread1 As New System.Threading.Thread(AddressOf counter1.Count)
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        TextBox2.Text = ""
        counter1.CountTo = TextBox1.Text
        AddHandler counter1.FinishedCounting, AddressOf _
    End Sub

When the thread in this example finished counting, it created a Finished CountingEvent event, which we handled by displaying the total count in a text box:

    Sub FinishedCountingEventHandler(ByVal Count As Integer)
        TextBox2.Text = Count
    End Sub

For more on how this example works, take a look at the discussion in the In Depth section of this chapter.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor