This documentation is archived and is not being maintained.

Thread.Join Method ()

Blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping.

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)

Public Sub Join
Dim instance As Thread

public void Join ()
public function Join ()
Not applicable.

Exception typeCondition


The caller attempted to join a thread that is in the ThreadState.Unstarted state.


The thread is interrupted while waiting.

Use this method to ensure a thread has terminated. The caller will block indefinitely if the thread does not terminate. If the thread has already terminated when Join is called, the method returns immediately.

This method changes the state of the calling thread to include ThreadState.WaitSleepJoin. You cannot invoke Join on a thread that is in the ThreadState.Unstarted state.

The following code example shows how to use Join to wait for a thread to terminate.

Option Explicit
Option Strict

Imports System
Imports System.Threading

Public Class IsThreadPool

    <MTAThread> _
    Shared Sub Main()
        Dim autoEvent As New AutoResetEvent(False)

        Dim regularThread As New Thread(AddressOf ThreadMethod)
        ThreadPool.QueueUserWorkItem(AddressOf WorkMethod, autoEvent)

        ' Wait for foreground thread to end.

        ' Wait for background thread to end.
    End Sub

    Shared Sub ThreadMethod()
        Console.WriteLine("ThreadOne, executing ThreadMethod, " & _
            "is from the thread pool? {0}", _
    End Sub

    Shared Sub WorkMethod(stateInfo As Object)
        Console.WriteLine("ThreadTwo, executing WorkMethod, " & _
            "is from the thread pool? {0}", _

        ' Signal that this thread is finished.
        DirectCast(stateInfo, AutoResetEvent).Set()
    End Sub

End Class

import System.*;
import System.Threading.*;
import System.Threading.Thread;

class IsThreadPool
    public static void main(String[] args)
        AutoResetEvent autoEvent = new AutoResetEvent(false);
        Thread regularThread = new Thread(new ThreadStart(ThreadMethod));

        ThreadPool.QueueUserWorkItem(new WaitCallback(WorkMethod), autoEvent);

        // Wait for foreground thread to end.

        // Wait for background thread to end.
    } //main

    static void ThreadMethod()
        Console.WriteLine("ThreadOne, executing ThreadMethod, " 
            +  "is {0}from the thread pool.", 
            ? "" : "not ");
    } //ThreadMethod

    static void WorkMethod(Object stateInfo)
        Console.WriteLine("ThreadTwo, executing WorkMethod, " + 
            "is {0}from the thread pool.",
            ? "" : "not ");

        // Signal that this thread is finished.
    } //WorkMethod
} //IsThreadPool

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0