thread_object.Join Method

Waits for a thread to become idle, with a timeout.   Returns -1 (True) if the thread is now idle or 0 (False) if the timeout time was exceeded.

status = thread_object.Join(millisecond_timeout )

Prerequisites

None

Parameters

millisecond_timeout

The maximum time to wait for the thread associated with thread_object to become idle. A value of 0 means do not wait, just test if the thread is idle. A value of -1 means do not timeout, wait forever for the thread.

Remarks

When this method is called, the calling thread waits until the thread associated with thread_object becomes idle, or until the specified timeout value is exceeded. The returned value of the method is -1 (True) if the thread is idle or if the thread does not exist. The returned value is 0 (False) if the thread exists and is not idle. Normally a returned value of 0 indicates that the timeout time has been exceeded. If the calling thread is suspended externally and then resumed during the Join method, the value 0 is returned even though the timeout time may not have been exceeded.

If the referenced thread is suspended or stops with an error, the Join method continues waiting. It only completes with True when the thread is idle or deleted.

Examples

Dim thread1 As New Thread(“Test”)' Create a thread object to execute the
' procedure Test in the current project
Dim status As Integer
thread1.Start() ' Start the thread
status = thread1.Join(10000) ' Wait for the thread to complete with a
' 10-second timeout.
If status Then
Console.Writeline(“thread1 is complete”)
End If

See Also

Thread Class | thread_object.ThreadState