System.Threading.Thread.Join Method

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

Syntax

public bool Join (int millisecondsTimeout)

Parameters

millisecondsTimeout
The number of milliseconds to wait for the thread to terminate.

Returns

true if the thread has terminated; false if the thread has not terminated after the amount of time specified by the millisecondsTimeout parameter has elapsed.

Exceptions

TypeReason
ArgumentOutOfRangeExceptionThe value of millisecondsTimeout is negative and is not equal to Timeout.Infinite .
System.Threading.ThreadStateExceptionThe caller attempted to join a thread that is in the ThreadState.Unstarted state.

Remarks

If Timeout.Infinite is specified for the millisecondsTimeout parameter, this method behaves identically to the Thread.Join method overload, except for the return value.

If the thread has already terminated when erload:System.Threading.Thread.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.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0