Export (0) Print
Expand All

IAsyncResult Interface

.NET Framework 1.1

The IAsyncResult interface is used to monitor and manage the asynchronous operation. It is returned from the begin operation and passed to the end operation to correlate the begin and end. The AsyncResult is passed to the callback if the callback is specified as part of the begin operation. The following code demonstrates the properties on the IAsyncResult interface that can be used to monitor the state of the asynchronous operation and to obtain the asynchronous state object that was optionally passed in the begin operation:

public interface IAsyncResult
{
  Object AsyncState { get; }
  WaitHandle AsyncWaitHandle { get; }
  bool CompletedSynchronously { get; }
  bool IsCompleted { get; }
}
  • AsyncState

    Returns the object that was provided as the last parameter as part of the begin operation method call.

  • AsyncWaitHandle

    The AsyncWaitHandle property returns the WaitHandle that can be used to perform a WaitHandle.WaitOne or WaitAny or WaitAll.

    Note   The object that implements IAsyncResult does not need to create the WaitHandle until the AsyncWaitHandle property is read; the timing is up to the implementer. If the implementer creates the WaitHandle, it is the responsibility of the implementer to signal the WaitHandle to terminate the wait at the appropriate time. For example, an AsyncResult terminates the wait on behalf of the caller when an asynchronously invoked method returns. Once created, the WaitHandle should be kept alive until the user calls the method that concludes the asynchronous operation. At that time the object behind AsyncWaitHandle can be discarded.
  • CompletedSynchronously

    The CompletedSynchronously property will be set to true if the begin operation call completed synchronously.

  • IsCompleted

    The IsCompleted property will be set to true after the server has completed processing of the call.

See Also

Asynchronous Design Pattern Overview | Asynchronous Method Signatures | AsyncCallback Delegate for Asynchronous Operations | Asynchronous Programming

Show:
© 2014 Microsoft