共用方式為


WaitHandle.WaitAll Method (array<WaitHandle[], Int32)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Waits for all the elements in the specified array to receive a signal, using an Int32 value to specify the time interval.

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

Syntax

'Declaration
Public Shared Function WaitAll ( _
    waitHandles As WaitHandle(), _
    millisecondsTimeout As Integer _
) As Boolean
public static bool WaitAll(
    WaitHandle[] waitHandles,
    int millisecondsTimeout
)

Parameters

  • waitHandles
    Type: array<System.Threading.WaitHandle[]
    An array that contains the objects for which the current instance will wait. This array cannot contain multiple references to the same object.

Return Value

Type: System.Boolean
true when every element in waitHandles has received a signal; otherwise, false.

Exceptions

Exception Condition
ArgumentNullException

The waitHandles parameter is nulla null reference (Nothing in Visual Basic). -or-

One or more of the objects in the waitHandles array is nulla null reference (Nothing in Visual Basic).

ArgumentException

The waitHandles array contains elements that are duplicates.

-or-

waitHandles is an array with no elements.

NotSupportedException

The number of objects in waitHandles is greater than the system permits.

ArgumentOutOfRangeException

millisecondsTimeout is a negative number other than -1, which represents an infinite time-out.

Remarks

If millisecondsTimeout is zero, the method does not block. It tests the state of the wait handles and returns immediately.

The WaitAll method returns when the wait terminates, either when all the handles are signaled or when a time-out occurs. On some implementations, if more than 64 handles are passed, a NotSupportedException is thrown. If there are duplicates in the array, the call fails with an ArgumentException.

If you call this method from a single-threaded apartment, and waitHandles contains more than one wait handle, the method deadlocks.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 WaitAll is present but not supported in Silverlight for Windows Phone.

Examples

The following example shows how to use this overload of the WaitAll method to report progress while waiting for multiple threads to finish. Each time the WaitAll method times out, the thread that was waiting reports progress to the user interface thread.

This code is part of a larger example provided for the WaitHandle class.

' Wait for ALL subtasks to complete, and show progress every 1/4 second if
' the WaitAll times out.

While Not WaitHandle.WaitAll(waitHandles, 250)

   ' If the WaitAll timed out, show progress.
   worker.ReportProgress(3)

End While
// Wait for ALL subtasks to complete, and show progress every 1/4 second if
// the WaitAll times out.

while (!WaitHandle.WaitAll(waitHandles, 250))
{
   // If the WaitAll timed out, show progress.
   worker.ReportProgress(3);
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.