Skip to main content
WaitHandleWaitOne Method

Blocks the current thread until the current WaitHandle receives a signal.

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

public virtual bool WaitOne()
virtual bool WaitOne()
abstract WaitOne : unit -> bool
override WaitOne : unit -> bool
Public Overridable Function WaitOne As Boolean

Return Value


true if the current instance receives a signal. If the current instance is never signaled, WaitOne never returns.

Exception Condition

The current instance has already been disposed.


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


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


AbandonedMutexException is new in the .NET Framework version 2.0. In previous versions, the WaitOne method returns true when a mutex is abandoned. An abandoned mutex often indicates a serious coding error. In the case of a system-wide mutex, it might indicate that an application has been terminated abruptly (for example, by using Windows Task Manager). The exception contains information useful for debugging.

The caller of this method blocks indefinitely until the current instance receives a signal. 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.

Calling this method overload is equivalent to calling the WaitOne method overload and specifying -1 or TimeoutInfinite for the first parameter and false for the second parameter.

Override this method to customize the behavior of derived classes.


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.

using System;
using System.Threading;

class WaitOne
    static AutoResetEvent autoEvent = new AutoResetEvent(false);

    static void Main()
        Console.WriteLine("Main starting.");

            new WaitCallback(WorkMethod), autoEvent);

        // Wait for work method to signal.
        Console.WriteLine("Work method signaled.\nMain ending.");

    static void WorkMethod(object stateInfo) 
        Console.WriteLine("Work starting.");

        // Simulate time spent working.
        Thread.Sleep(new Random().Next(100, 2000));

        // Signal that work is finished.
        Console.WriteLine("Work ending.");
Imports System
Imports System.Threading

Public Class WaitOne

    Shared autoEvent As New AutoResetEvent(False)

    <MTAThread> _
    Shared Sub Main()
        Console.WriteLine("Main starting.")

        ThreadPool.QueueUserWorkItem(AddressOf WorkMethod, autoEvent)

        ' Wait for work method to signal.
        Console.WriteLine("Work method signaled.")
        Console.WriteLine("Main ending.")
    End Sub

    Shared Sub WorkMethod(stateInfo As Object) 
        Console.WriteLine("Work starting.")

        ' Simulate time spent working.
        Thread.Sleep(New Random().Next(100, 2000))

        ' Signal that work is finished.
        Console.WriteLine("Work ending.")
        CType(stateInfo, AutoResetEvent).Set()
    End Sub

End Class
using namespace System;
using namespace System::Threading;
ref class WaitOne

   static void WorkMethod( Object^ stateInfo )
      Console::WriteLine( "Work starting." );

      // Simulate time spent working.
      Thread::Sleep( (gcnew Random)->Next( 100, 2000 ) );

      // Signal that work is finished.
      Console::WriteLine( "Work ending." );


int main()
   Console::WriteLine( "Main starting." );
   AutoResetEvent^ autoEvent = gcnew AutoResetEvent( false );
   ThreadPool::QueueUserWorkItem( gcnew WaitCallback( &WaitOne::WorkMethod ), autoEvent );

   // Wait for work method to signal.
   autoEvent->WaitOne(  );
   Console::WriteLine( "Work method signaled.\nMain ending." );
Version Information
Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top