Programming Tutorials

Joining Threads in VB.net

By: Steven Holzner in VB.net Tutorials on 2010-10-23  

You can use the Join method to wait until a thread finishes; this method will return when the thread is finished executing. Here are the various forms of this method:

  • Sub Join- Waits for a thread to die.

  • Function Join(TimeOut As Integer) As Boolean -Waits for the thread to die or for a specific timeout, given as a number of milliseconds, to elapse. Returns True if the thread died, False if the call timed out.

  • Function Join(TimeOut As TimeSpan) As Boolean- Waits for the thread to die or for a specific timeout, given as a TimeSpan object, to elapse. Returns True if the thread died, False if the call timed out.

Example:

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        Thread1.Start()
        Thread2.Start()
        Thread1.Join()
        Thread2.Join()
        TextBox1.Text = c.Total
    End Sub





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)