Gets a WaitHandle that encapsulates Win32 synchronization handles, and allows the implementation of various synchronization schemes.
Assembly: mscorlib (in mscorlib.dll)
abstract AsyncWaitHandle : WaitHandle with get override AsyncWaitHandle : WaitHandle with get
Property ValueType: System.Threading.WaitHandle
A WaitHandle that encapsulates Win32 synchronization handles, and allows the implementation of various synchronization schemes.
The WaitHandle returned by this method is automatically signaled when the asynchronous operation has completed.
The wait handle is not closed automatically when you call EndInvoke on the delegate that was used to make the asynchronous method call. If you release all references to the wait handle, system resources are freed when garbage collection reclaims the wait handle. To free the system resources as soon as you are finished using the wait handle, call the WaitHandle.Close method. Garbage collection works more efficiently when disposable objects are explicitly closed or disposed.
The WaitHandle contained in the property can be used to block the current thread until the asynchronous call is complete. However the WaitHandle will ignore the AsyncCallback, if one was specified during the BeginInvoke call. Therefore, a situation can occur where the application shuts down before the AsyncCallback has finished executing, even if a WaitHandle is used to block until the asynchronous call completion. For an example of such a situation, see the example for the AsyncResult class, and remove the Thread.Sleep statement.
The following example demonstrates how to use the property to get a WaitHandle, and how to wait for an asynchronous call on a delegate. The WaitHandle is signaled when the asynchronous call completes, and you can wait for it by calling the WaitOne method.
The example consists of two classes, the class that contains the method which is called asynchronously, and the class that contains the Main method that makes the call.
For more information and more examples of calling methods asynchronously by using delegates, see Calling Synchronous Methods Asynchronously.