WaitHandle.WaitOne Method (Int32)

 

Blocks the current thread until the current WaitHandle receives a signal, using a 32-bit signed integer to specify the time interval in milliseconds.

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

abstract WaitOne : 
        millisecondsTimeout:int -> bool
override WaitOne : 
        millisecondsTimeout:int -> bool

Parameters

millisecondsTimeout
Type: System.Int32

The number of milliseconds to wait, or Timeout.Infinite (-1) to wait indefinitely.

Return Value

Type: System.Boolean

true if the current instance receives a signal; otherwise, false.

Exception Condition
ObjectDisposedException

The current instance has already been disposed.

ArgumentOutOfRangeException

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

AbandonedMutexException

The wait completed because a thread exited without releasing a mutex. This exception is not thrown on Windows 98 or Windows Millennium Edition.

InvalidOperationException

The current instance is a transparent proxy for a WaitHandle in another application domain.

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

The caller of this method blocks until the current instance receives a signal or a time-out occurs. Use this method to block until a WaitHandle receives a signal from another thread, such as is generated when an asynchronous operation completes. For more information, see the IAsyncResult interface.

Override this method to customize the behavior of derived classes.

Calling this method overload is the same as calling the WaitOne(Int32, Boolean) overload and specifying false for exitContext.

The following code example shows how to use a wait handle to keep a process from terminating while it waits for a background thread to finish executing.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: