System.IAsyncResult Interface

public interface IAsyncResult

Assembly

mscorlib

Library

BCL

Summary

Supported by objects that represent the state of an asynchronous operation.

Description

An object that supports the IAsyncResult interface stores state information for an asynchronous operation, and provides a synchronization object to allow threads to be signaled when the operation completes.

IAsyncResult objects are returned by methods that begin asynchronous operations, such as System.IO.FileStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object), and are passed to methods used to complete asynchronous operations, such as System.IO.FileStream.EndRead(System.IAsyncResult). IAsyncResult objects are also passed to methods invoked by AsyncCallback delegates when an asynchronous operation completes.

See Also

System Namespace

Members

IAsyncResult Properties

IAsyncResult.AsyncState Property
IAsyncResult.AsyncWaitHandle Property
IAsyncResult.CompletedSynchronously Property
IAsyncResult.IsCompleted Property


IAsyncResult.AsyncState Property

object AsyncState { get; }

Summary

Gets the user-provided state object supplied at the time the asynchronous operation was started.

Property Value

The supplied Object.

Description

[Behaviors: The object returned by this property is required to be the object specified as the last parameter to methods that begin asynchronous operations, such as System.IO.FileStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object).

This property is read-only.

]

[Overrides: Implement this property to allow the caller of an asynchronous operation to obtain an application-defined object specified at the start of the operation. ]

[Usage: The object returned by this property can be used to pass state information for the asynchronous operation to a AsyncCallback delegate. ]

See Also

System.IAsyncResult Interface, System Namespace

IAsyncResult.AsyncWaitHandle Property

WaitHandle AsyncWaitHandle { get; }

Summary

Gets a WaitHandle that can be used to block a thread until an asynchronous operation completes.

Property Value

A WaitHandle that is signaled when an asynchronous operation completes.

Description

[Behaviors: The object returned by System.IAsyncResult.AsyncWaitHandle can be allocated in advance or on demand. However, once allocated it is required to be kept alive until the user calls a method that ends the asynchronous operation, such as System.IO.FileStream.EndRead(System.IAsyncResult). Only after the operation completes or is canceled, can the object be disposed of.

[Note: WaitHandle supplies methods that support waiting for synchronization objects to become signaled, such as System.Threading.WaitHandle.WaitOne(System.Int32,System.Boolean) .]

This property is read-only.

]

[Usage: Clients that wait for the operation to complete (as opposed to polling), use this property to obtain a synchronization object to wait on.

]

See Also

System.IAsyncResult Interface, System Namespace

IAsyncResult.CompletedSynchronously Property

bool CompletedSynchronously { get; }

Summary

Gets a Boolean value that specifies whether the asynchronous operation completed synchronously.

Property Value

true if the operation synchronously; otherwise false .

Description

[Behaviors: As described above.

[Note: Most implementations of the IAsyncResult interface will not use this property, and should return false .]

This property is read-only.

]

[Usage: Use this property to determine if the asynchronous operation completed synchronously. For example, this property can return true for an asynchronous IO operation if the IO request was small. ]

See Also

System.IAsyncResult Interface, System Namespace

IAsyncResult.IsCompleted Property

bool IsCompleted { get; }

Summary

Gets a Boolean value that specifies whether an asynchronous operation has completed.

Property Value

true if the operation has completed; otherwise false .

Description

[Behaviors: As described above.

This property is read-only.

]

[Usage: Clients that poll for operation status (as opposed to waiting on a synchronization object) use this property to determine the status of the operation.

]

See Also

System.IAsyncResult Interface, System Namespace