Show / Hide Table of Contents

Class AsyncResult

A lightweight net35-compatible asynchronous operation (promise) for Unity3d.

Inheritance
Object
AsyncResult
AsyncCompletionSource
AsyncResult<TResult>
Implements
IAsyncOperation
IAsyncOperationCallbacks
IAsyncCancellable
IAsyncResult
IDisposable
IAsyncContinuation
IEnumerator
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: UnityFx.Async
Assembly: UnityFx.Async-netstandard2.0.dll
Syntax
public class AsyncResult : IAsyncOperation, IAsyncOperationCallbacks, IAsyncCancellable, IAsyncResult, IDisposable, IAsyncContinuation, IEnumerator
Remarks

This class is the core entity of the library. In many aspects it mimics Task interface and behaviour. For example, any AsyncResult instance can have any number of continuations (added either explicitly via AddCompletionCallback call or implicitly using async/await keywords). These continuations can be invoked on a an arbitrary SynchronizationContext. The class can be used to implement Asynchronous Programming Model (APM). There are operation state accessors that can be used exactly like corresponding properties of Task. While the class implements IDisposable disposing is only required if AsyncWaitHandle property was used.

Constructors

| Improve this Doc View Source

AsyncResult()

Initializes a new instance of the AsyncResult class.

Declaration
public AsyncResult()
| Improve this Doc View Source

AsyncResult(AsyncCallback, Object)

Initializes a new instance of the AsyncResult class.

Declaration
public AsyncResult(AsyncCallback asyncCallback, object asyncState)
Parameters
Type Name Description
AsyncCallback asyncCallback

User-defined completion callback.

Object asyncState

User-defined data returned by AsyncState.

| Improve this Doc View Source

AsyncResult(AsyncCreationOptions)

Initializes a new instance of the AsyncResult class with the specified CreationOptions.

Declaration
public AsyncResult(AsyncCreationOptions options)
Parameters
Type Name Description
AsyncCreationOptions options

The AsyncCreationOptions used to customize the operation's behavior.

| Improve this Doc View Source

AsyncResult(AsyncCreationOptions, AsyncCallback, Object)

Initializes a new instance of the AsyncResult class.

Declaration
public AsyncResult(AsyncCreationOptions options, AsyncCallback asyncCallback, object asyncState)
Parameters
Type Name Description
AsyncCreationOptions options

The AsyncCreationOptions used to customize the operation's behavior.

AsyncCallback asyncCallback

User-defined completion callback.

Object asyncState

User-defined data returned by AsyncState.

| Improve this Doc View Source

AsyncResult(AsyncCreationOptions, Object)

Initializes a new instance of the AsyncResult class.

Declaration
public AsyncResult(AsyncCreationOptions options, object asyncState)
Parameters
Type Name Description
AsyncCreationOptions options

The AsyncCreationOptions used to customize the operation's behavior.

Object asyncState

User-defined data returned by AsyncState.

| Improve this Doc View Source

AsyncResult(AsyncOperationStatus)

Initializes a new instance of the AsyncResult class with the specified Status.

Declaration
public AsyncResult(AsyncOperationStatus status)
Parameters
Type Name Description
AsyncOperationStatus status

Initial value of the Status property.

| Improve this Doc View Source

AsyncResult(AsyncOperationStatus, AsyncCallback, Object)

Initializes a new instance of the AsyncResult class with the specified Status.

Declaration
public AsyncResult(AsyncOperationStatus status, AsyncCallback asyncCallback, object asyncState)
Parameters
Type Name Description
AsyncOperationStatus status

Initial value of the Status property.

AsyncCallback asyncCallback

User-defined completion callback.

Object asyncState

User-defined data returned by AsyncState.

| Improve this Doc View Source

AsyncResult(AsyncOperationStatus, Object)

Initializes a new instance of the AsyncResult class with the specified Status.

Declaration
public AsyncResult(AsyncOperationStatus status, object asyncState)
Parameters
Type Name Description
AsyncOperationStatus status

Initial value of the Status property.

Object asyncState

User-defined data returned by AsyncState.

| Improve this Doc View Source

AsyncResult(AsyncOperationStatus, AsyncCreationOptions)

Initializes a new instance of the AsyncResult class with the specified Status and CreationOptions.

Declaration
public AsyncResult(AsyncOperationStatus status, AsyncCreationOptions options)
Parameters
Type Name Description
AsyncOperationStatus status

Initial value of the Status property.

AsyncCreationOptions options

The AsyncCreationOptions used to customize the operation's behavior.

| Improve this Doc View Source

AsyncResult(AsyncOperationStatus, AsyncCreationOptions, AsyncCallback, Object)

Initializes a new instance of the AsyncResult class with the specified Status and CreationOptions.

Declaration
public AsyncResult(AsyncOperationStatus status, AsyncCreationOptions options, AsyncCallback asyncCallback, object asyncState)
Parameters
Type Name Description
AsyncOperationStatus status

Initial value of the Status property.

AsyncCreationOptions options

The AsyncCreationOptions used to customize the operation's behavior.

AsyncCallback asyncCallback

User-defined completion callback.

Object asyncState

User-defined data returned by AsyncState.

| Improve this Doc View Source

AsyncResult(AsyncOperationStatus, AsyncCreationOptions, Object)

Initializes a new instance of the AsyncResult class with the specified Status and CreationOptions.

Declaration
public AsyncResult(AsyncOperationStatus status, AsyncCreationOptions options, object asyncState)
Parameters
Type Name Description
AsyncOperationStatus status

Initial value of the Status property.

AsyncCreationOptions options

The AsyncCreationOptions used to customize the operation's behavior.

Object asyncState

User-defined data returned by AsyncState.

Properties

| Improve this Doc View Source

AsyncState

Gets a user-defined object that qualifies or contains information about an asynchronous operation.

Declaration
public object AsyncState { get; }
Property Value
Type Description
Object

A user-defined object that qualifies or contains information about an asynchronous operation.

| Improve this Doc View Source

AsyncWaitHandle

Gets a WaitHandle that is used to wait for an asynchronous operation to complete.

Declaration
public WaitHandle AsyncWaitHandle { get; }
Property Value
Type Description
WaitHandle

A WaitHandle that is used to wait for an asynchronous operation to complete.

Remarks

The handle is lazily allocated on the first property access. Make sure to call Dispose() when the operation instance is not in use.

See Also
Dispose()
| Improve this Doc View Source

CanceledOperation

Gets an operation that's already been canceled.

Declaration
public static AsyncResult CanceledOperation { get; }
Property Value
Type Description
AsyncResult

Canceled IAsyncOperation instance.

Remarks

Note that Dispose() call have no effect on operations returned with the property. May not always return the same instance.

| Improve this Doc View Source

CompletedOperation

Gets an operation that's already been completed successfully.

Declaration
public static AsyncResult CompletedOperation { get; }
Property Value
Type Description
AsyncResult

Completed IAsyncOperation instance.

Remarks

Note that Dispose() call have no effect on operations returned with the property. May not always return the same instance.

| Improve this Doc View Source

CompletedSynchronously

Gets a value indicating whether the asynchronous operation completed synchronously.

Declaration
public bool CompletedSynchronously { get; }
Property Value
Type Description
Boolean

true if the asynchronous operation completed synchronously; otherwise, false.

Remarks

For the vast majority of cases this is false. Do not rely on this vlaue.

See Also
IsCompleted
| Improve this Doc View Source

CreationOptions

Gets the AsyncCreationOptions used to create this operation.

Declaration
public AsyncCreationOptions CreationOptions { get; }
Property Value
Type Description
AsyncCreationOptions

The operation creation options.

| Improve this Doc View Source

DefaultSynchronizationContext

Gets or sets a reference to SynchronizationContext that is used for majority of continuations.

Declaration
public static SynchronizationContext DefaultSynchronizationContext { get; set; }
Property Value
Type Description
SynchronizationContext

An instance of SynchronizationContext that is used as default one. Initial value is null.

Remarks

This property is supposed to be used as allocation optimization in applications working mostly with single SynchronizationContext instance (such as Unity3d applications). Usually this should be set to a context attached to the app UI thread.

| Improve this Doc View Source

Exception

Gets an exception that caused the operation to end prematurely. If the operation completed successfully or has not yet thrown any exceptions, this will return null.

Declaration
public Exception Exception { get; }
Property Value
Type Description
Exception

An exception that caused the operation to end prematurely.

| Improve this Doc View Source

FaultedOperation

Gets a faulted operation.

Declaration
public static AsyncResult FaultedOperation { get; }
Property Value
Type Description
AsyncResult

Faulted IAsyncOperation instance.

Remarks

Note that Dispose() call have no effect on operations returned with the property. May not always return the same instance.

| Improve this Doc View Source

Id

Gets a unique ID for the operation instance.

Declaration
public int Id { get; }
Property Value
Type Description
Int32

Unique non-zero identifier of the operation instance.

| Improve this Doc View Source

IsCanceled

Gets a value indicating whether the operation completed due to being canceled (i.e. with Canceled status).

Declaration
public bool IsCanceled { get; }
Property Value
Type Description
Boolean

A value indicating whether the operation was canceled.

| Improve this Doc View Source

IsCancellationRequested

Gets a value indicating whether the operation cancellation was requested.

Declaration
protected bool IsCancellationRequested { get; }
Property Value
Type Description
Boolean

A value indicating whether the operation cancellation was requested.

| Improve this Doc View Source

IsCompleted

Gets a value indicating whether the asynchronous operation has completed.

Declaration
public bool IsCompleted { get; }
Property Value
Type Description
Boolean

true if the operation is complete; otherwise, false.

See Also
CompletedSynchronously
| Improve this Doc View Source

IsCompletedSuccessfully

Gets a value indicating whether the operation completed successfully (i.e. with RanToCompletion status).

Declaration
public bool IsCompletedSuccessfully { get; }
Property Value
Type Description
Boolean

A value indicating whether the operation completed successfully.

| Improve this Doc View Source

IsDisposed

Gets a value indicating whether the operation instance is disposed.

Declaration
protected bool IsDisposed { get; }
Property Value
Type Description
Boolean

A value indicating whether the operation is disposed.

| Improve this Doc View Source

IsFaulted

Gets a value indicating whether the operation completed due to an unhandled exception (i.e. with Faulted status).

Declaration
public bool IsFaulted { get; }
Property Value
Type Description
Boolean

A value indicating whether the operation has failed.

| Improve this Doc View Source

IsRunning

Gets a value indicating whether the operation in running.

Declaration
public bool IsRunning { get; }
Property Value
Type Description
Boolean

A value indicating whether the operation is running.

| Improve this Doc View Source

IsStarted

Gets a value indicating whether the operation has been started.

Declaration
public bool IsStarted { get; }
Property Value
Type Description
Boolean

A value indicating whether the operation has been started.

| Improve this Doc View Source

Progress

Gets the operation progress in range [0, 1].

Declaration
public float Progress { get; }
Property Value
Type Description
Single

Progress of the operation in range [0, 1].

| Improve this Doc View Source

Status

Gets the operation status identifier.

Declaration
public AsyncOperationStatus Status { get; }
Property Value
Type Description
AsyncOperationStatus

Identifier of the operation status.

Methods

| Improve this Doc View Source

AddCompletionCallback(Object, SynchronizationContext)

Adds a completion callback to be executed after the operation has completed. If the operation is completed action is invoked on the syncContext specified.

Declaration
public void AddCompletionCallback(object action, SynchronizationContext syncContext)
Parameters
Type Name Description
Object action

The callback to be executed when the operation has completed. Can be one of Action, System.Action<T> (with IAsyncOperation argument type), AsyncCallback, IAsyncContinuation or AsyncCompletedEventHandler.

SynchronizationContext syncContext

If not null method attempts to marshal the continuation to the synchronization context. Otherwise the callback is invoked on a thread that initiated the operation completion.

Remarks

The action is invoked on a SynchronizationContext specified. Throwing an exception from the callback might cause unspecified behaviour.

Exceptions
Type Condition
ArgumentNullException

Thrown if action is null.

ObjectDisposedException

Thrown is the operation has been disposed.

See Also
AddProgressCallback(Object, SynchronizationContext)
RemoveCallback(Object)
| Improve this Doc View Source

AddProgressCallback(Object, SynchronizationContext)

Adds a callback to be executed when the operation progress has changed. If the operation is completed action is invoked on the syncContext specified.

Declaration
public void AddProgressCallback(object action, SynchronizationContext syncContext)
Parameters
Type Name Description
Object action

The callback to be executed when the operation progress has changed.

SynchronizationContext syncContext

If not null method attempts to marshal the continuation to the synchronization context. Otherwise the callback is invoked on a thread that initiated the operation.

Remarks

The action is invoked on a SynchronizationContext specified. Throwing an exception from the callback might cause unspecified behaviour.

Exceptions
Type Condition
ArgumentNullException

Thrown if action is null.

ObjectDisposedException

Thrown is the operation has been disposed.

See Also
AddCompletionCallback(Object, SynchronizationContext)
RemoveCallback(Object)
| Improve this Doc View Source

Cancel()

Initiates cancellation of an asynchronous operation.

Declaration
public void Cancel()
Remarks

There is no guarantee that this call will actually cancel the operation or that the operation will be cancelled immidiately. SuppressCancellation can be used to suppress this method for a specific operation instance.

| Improve this Doc View Source

Delay(Int32)

Creates an operation that completes after a time delay.

Declaration
public static AsyncResult Delay(int millisecondsDelay)
Parameters
Type Name Description
Int32 millisecondsDelay

The number of milliseconds to wait before completing the returned operation, or Infinite (-1) to wait indefinitely.

Returns
Type Description
AsyncResult

An operation that represents the time delay.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if the millisecondsDelay is less than -1.

See Also
Delay(Int32, IAsyncUpdateSource)
Delay(Single)
Delay(TimeSpan)
| Improve this Doc View Source

Delay(Int32, IAsyncUpdateSource)

Creates an operation that completes after a time delay. This method creates a more effecient operation than Delay(Int32) but requires a specialized update source.

Declaration
public static AsyncResult Delay(int millisecondsDelay, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
Int32 millisecondsDelay

The number of milliseconds to wait before completing the returned operation, or Infinite (-1) to wait indefinitely.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult

An operation that represents the time delay.

Exceptions
Type Condition
ArgumentNullException

Thrown if updateSource is null.

ArgumentOutOfRangeException

Thrown if the millisecondsDelay is less than -1.

See Also
Delay(Int32)
Delay(Single, IAsyncUpdateSource)
Delay(TimeSpan, IAsyncUpdateSource)
| Improve this Doc View Source

Delay(Single)

Creates an operation that completes after a specified time interval.

Declaration
public static AsyncResult Delay(float secondsDelay)
Parameters
Type Name Description
Single secondsDelay

The number of seconds to wait before completing the returned operation, or Infinite (-1) to wait indefinitely.

Returns
Type Description
AsyncResult

An operation that represents the time delay.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if the secondsDelay represents a negative time interval.

See Also
Delay(Single, IAsyncUpdateSource)
Delay(Int32)
Delay(TimeSpan)
| Improve this Doc View Source

Delay(Single, IAsyncUpdateSource)

Creates an operation that completes after a specified time interval. This method creates a more effecient operation than Delay(Single) but requires a specialized update source.

Declaration
public static AsyncResult Delay(float secondsDelay, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
Single secondsDelay

The number of seconds to wait before completing the returned operation, or Infinite (-1) to wait indefinitely.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult

An operation that represents the time delay.

Exceptions
Type Condition
ArgumentNullException

Thrown if updateSource is null.

ArgumentOutOfRangeException

Thrown if the secondsDelay represents a negative time interval other than TimeSpan.FromMillseconds(-1).

See Also
Delay(Single)
Delay(Int32, IAsyncUpdateSource)
Delay(TimeSpan, IAsyncUpdateSource)
| Improve this Doc View Source

Delay(TimeSpan)

Creates an operation that completes after a specified time interval.

Declaration
public static AsyncResult Delay(TimeSpan delay)
Parameters
Type Name Description
TimeSpan delay

The time span to wait before completing the returned operation, or TimeSpan.FromMilliseconds(-1) to wait indefinitely.

Returns
Type Description
AsyncResult

An operation that represents the time delay.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if the delay represents a negative time interval other than TimeSpan.FromMillseconds(-1).

See Also
Delay(TimeSpan, IAsyncUpdateSource)
Delay(Int32)
Delay(Single)
| Improve this Doc View Source

Delay(TimeSpan, IAsyncUpdateSource)

Creates an operation that completes after a specified time interval. This method creates a more effecient operation than Delay(TimeSpan) but requires a specialized update source.

Declaration
public static AsyncResult Delay(TimeSpan delay, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
TimeSpan delay

The time span to wait before completing the returned operation, or TimeSpan.FromMilliseconds(-1) to wait indefinitely.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult

An operation that represents the time delay.

Exceptions
Type Condition
ArgumentNullException

Thrown if updateSource is null.

ArgumentOutOfRangeException

Thrown if the delay represents a negative time interval other than TimeSpan.FromMillseconds(-1).

See Also
Delay(TimeSpan)
Delay(Int32, IAsyncUpdateSource)
Delay(Single, IAsyncUpdateSource)
| Improve this Doc View Source

Dispose()

Disposes the AsyncResult, releasing all of its unmanaged resources. This call is only required if AsyncWaitHandle was accessed; otherwise it is safe to ignore this method.

Declaration
public void Dispose()
Remarks

Unlike most of the members of AsyncResult, this method is not thread-safe. Also, Dispose() may only be called on an AsyncResult that is in one of the final states: RanToCompletion, Faulted or Canceled.

Exceptions
Type Condition
InvalidOperationException

Thrown if the operation is not completed.

See Also
Dispose(Boolean)
| Improve this Doc View Source

Dispose(Boolean)

Releases unmanaged resources used by the object.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

A langword_csharp_bool value that indicates whether this method is being called due to a call to Dispose().

Remarks

Unlike most of the members of AsyncResult, this method is not thread-safe. Do not throw exceptions in Dispose(Boolean).

See Also
Dispose()
ThrowIfDisposed()
| Improve this Doc View Source

FromAction(Action)

Creates a completed IAsyncOperation that represents result of the action specified.

Declaration
public static AsyncResult FromAction(Action action)
Parameters
Type Name Description
Action action

The delegate to execute.

Returns
Type Description
AsyncResult

A completed operation that represents action result.

Exceptions
Type Condition
ArgumentNullException

Thrown if action is null.

See Also
FromAction<T>(Action<T>, T)
FromAction(SendOrPostCallback, Object)
FromAction<TResult>(Func<TResult>)
| Improve this Doc View Source

FromAction(Action, CancellationToken)

Creates a completed IAsyncOperation that represents result of the action specified.

Declaration
public static AsyncResult FromAction(Action action, CancellationToken cancellationToken)
Parameters
Type Name Description
Action action

The delegate to execute.

CancellationToken cancellationToken

A cancellation token to check before executing the action.

Returns
Type Description
AsyncResult

A completed operation that represents action result.

Exceptions
Type Condition
ArgumentNullException

Thrown if action is null.

See Also
FromAction(Action)
| Improve this Doc View Source

FromAction(Delegate, Object[])

Creates a completed IAsyncOperation that represents result of the callback specified.

Declaration
public static AsyncResult<object> FromAction(Delegate callback, object[] args)
Parameters
Type Name Description
Delegate callback

The delegate to execute.

Object[] args

Arguments of the callback.

Returns
Type Description
AsyncResult<Object>

A completed operation that represents the callback result.

Exceptions
Type Condition
ArgumentNullException

Thrown if callback is null.

See Also
FromAction(Action)
FromAction(SendOrPostCallback, Object)
| Improve this Doc View Source

FromAction(SendOrPostCallback, Object)

Creates a completed IAsyncOperation that represents result of the callback specified.

Declaration
public static AsyncResult FromAction(SendOrPostCallback callback, object state)
Parameters
Type Name Description
SendOrPostCallback callback

The delegate to execute.

Object state

User-defained state to pass to the callback.

Returns
Type Description
AsyncResult

A completed operation that represents callback result.

Exceptions
Type Condition
ArgumentNullException

Thrown if callback is null.

See Also
FromAction(Action)
FromAction<T>(Action<T>, T)
FromAction<TResult>(Func<TResult>)
| Improve this Doc View Source

FromAction<T>(Action<T>, T)

Creates a completed IAsyncOperation that represents result of the action specified.

Declaration
public static AsyncResult FromAction<T>(Action<T> action, T state)
Parameters
Type Name Description
System.Action<T> action

The delegate to execute.

T state

User-defained state to pass to the action.

Returns
Type Description
AsyncResult

A completed operation that represents action result.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown if action is null.

See Also
FromAction(Action)
FromAction(SendOrPostCallback, Object)
FromAction<TResult>(Func<TResult>)
| Improve this Doc View Source

FromAction<TResult>(Func<TResult>)

Creates a completed IAsyncOperation<TResult> that represents result of the action specified.

Declaration
public static AsyncResult<TResult> FromAction<TResult>(Func<TResult> action)
Parameters
Type Name Description
System.Func<TResult> action

The delegate to execute.

Returns
Type Description
AsyncResult<TResult>

A completed operation that represents action result.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if action is null.

See Also
FromAction(Action)
FromAction<T, TResult>(Func<T, TResult>, T)
| Improve this Doc View Source

FromAction<TResult>(Func<TResult>, CancellationToken)

Creates a completed IAsyncOperation<TResult> that represents result of the action specified.

Declaration
public static AsyncResult<TResult> FromAction<TResult>(Func<TResult> action, CancellationToken cancellationToken)
Parameters
Type Name Description
System.Func<TResult> action

The delegate to execute.

CancellationToken cancellationToken

A cancellation token to check before executing the action.

Returns
Type Description
AsyncResult<TResult>

A completed operation that represents action result.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if action is null.

See Also
FromAction<TResult>(Func<TResult>)
| Improve this Doc View Source

FromAction<T, TResult>(Func<T, TResult>, T)

Creates a completed IAsyncOperation that represents result of the action specified.

Declaration
public static AsyncResult<TResult> FromAction<T, TResult>(Func<T, TResult> action, T state)
Parameters
Type Name Description
System.Func<T, TResult> action

The delegate to execute.

T state

User-defained state to pass to the action.

Returns
Type Description
AsyncResult<TResult>

A completed operation that represents action result.

Type Parameters
Name Description
T
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if action is null.

See Also
FromAction<T>(Action<T>, T)
FromAction<TResult>(Func<TResult>)
| Improve this Doc View Source

FromCanceled()

Creates a IAsyncOperation that is canceled.

Declaration
public static AsyncResult FromCanceled()
Returns
Type Description
AsyncResult

A canceled operation.

See Also
FromCanceled(Object)
FromException(Exception)
FromResult<T>(T)
| Improve this Doc View Source

FromCanceled(Object)

Creates a IAsyncOperation that is canceled.

Declaration
public static AsyncResult FromCanceled(object asyncState)
Parameters
Type Name Description
Object asyncState

User-defined data returned by AsyncState.

Returns
Type Description
AsyncResult

A canceled operation.

See Also
FromCanceled()
FromException(Exception)
FromResult<T>(T, Object)
| Improve this Doc View Source

FromCanceled<T>()

Creates a IAsyncOperation<TResult> that is canceled.

Declaration
public static AsyncResult<T> FromCanceled<T>()
Returns
Type Description
AsyncResult<T>

A canceled operation.

Type Parameters
Name Description
T
See Also
FromCanceled<T>(Object)
FromException<T>(Exception)
FromResult<T>(T)
| Improve this Doc View Source

FromCanceled<T>(Object)

Creates a IAsyncOperation<TResult> that is canceled.

Declaration
public static AsyncResult<T> FromCanceled<T>(object asyncState)
Parameters
Type Name Description
Object asyncState

User-defined data returned by AsyncState.

Returns
Type Description
AsyncResult<T>

A canceled operation.

Type Parameters
Name Description
T
See Also
FromCanceled<T>()
FromException<T>(Exception)
FromResult<T>(T, Object)
| Improve this Doc View Source

FromException(Exception)

Creates a IAsyncOperation that has completed with a specified exception.

Declaration
public static AsyncResult FromException(Exception exception)
Parameters
Type Name Description
Exception exception

The exception to complete the operation with.

Returns
Type Description
AsyncResult

A faulted operation.

Exceptions
Type Condition
ArgumentNullException

Thrown if exception is null.

See Also
FromException(Exception, Object)
FromException(String)
FromCanceled()
FromResult<T>(T)
| Improve this Doc View Source

FromException(Exception, Object)

Creates a IAsyncOperation that has completed with a specified exception.

Declaration
public static AsyncResult FromException(Exception exception, object asyncState)
Parameters
Type Name Description
Exception exception

The exception to complete the operation with.

Object asyncState

User-defined data returned by AsyncState.

Returns
Type Description
AsyncResult

A faulted operation.

Exceptions
Type Condition
ArgumentNullException

Thrown if exception is null.

See Also
FromException(Exception)
FromException(String, Object)
FromCanceled(Object)
FromResult<T>(T, Object)
| Improve this Doc View Source

FromException(String)

Creates a IAsyncOperation that has completed with the specified error message.

Declaration
public static AsyncResult FromException(string message)
Parameters
Type Name Description
String message

An exception message.

Returns
Type Description
AsyncResult

A faulted operation.

See Also
FromException(Exception)
FromCanceled()
FromResult<T>(T)
| Improve this Doc View Source

FromException(String, Object)

Creates a IAsyncOperation that has completed with a specified error message.

Declaration
public static AsyncResult FromException(string message, object asyncState)
Parameters
Type Name Description
String message

An exception message.

Object asyncState

User-defined data returned by AsyncState.

Returns
Type Description
AsyncResult

A faulted operation.

See Also
FromException(Exception, Object)
FromCanceled(Object)
FromResult<T>(T, Object)
| Improve this Doc View Source

FromException<T>(Exception)

Creates a IAsyncOperation<TResult> that has completed with a specified exception.

Declaration
public static AsyncResult<T> FromException<T>(Exception exception)
Parameters
Type Name Description
Exception exception

The exception to complete the operation with.

Returns
Type Description
AsyncResult<T>

A faulted operation.

Type Parameters
Name Description
T
See Also
FromException(String)
FromException<T>(Exception, Object)
FromCanceled<T>()
FromResult<T>(T)
| Improve this Doc View Source

FromException<T>(Exception, Object)

Creates a IAsyncOperation<TResult> that has completed with a specified exception.

Declaration
public static AsyncResult<T> FromException<T>(Exception exception, object asyncState)
Parameters
Type Name Description
Exception exception

The exception to complete the operation with.

Object asyncState

User-defined data returned by AsyncState.

Returns
Type Description
AsyncResult<T>

A faulted operation.

Type Parameters
Name Description
T
See Also
FromException(String, Object)
FromException<T>(Exception)
FromCanceled<T>(Object)
FromResult<T>(T, Object)
| Improve this Doc View Source

FromException<T>(String)

Creates a IAsyncOperation<TResult> that has completed with a specified error message.

Declaration
public static AsyncResult<T> FromException<T>(string message)
Parameters
Type Name Description
String message

An exception message.

Returns
Type Description
AsyncResult<T>

A faulted operation.

Type Parameters
Name Description
T
See Also
FromException<T>(Exception)
FromCanceled<T>()
FromResult<T>(T)
| Improve this Doc View Source

FromException<T>(String, Object)

Creates a IAsyncOperation<TResult> that has completed with a specified error message.

Declaration
public static AsyncResult<T> FromException<T>(string message, object asyncState)
Parameters
Type Name Description
String message

An exception message.

Object asyncState

User-defined data returned by AsyncState.

Returns
Type Description
AsyncResult<T>

A faulted operation.

Type Parameters
Name Description
T
See Also
FromException<T>(Exception, Object)
FromCanceled<T>(Object)
FromResult<T>(T, Object)
| Improve this Doc View Source

FromObservable<T>(IObservable<T>)

Creates a IAsyncOperation<TResult> instance that can be used to track the source observable.

Declaration
public static AsyncResult<T> FromObservable<T>(IObservable<T> observable)
Parameters
Type Name Description
System.IObservable<T> observable

The source observable.

Returns
Type Description
AsyncResult<T>

Returns an IAsyncOperation<TResult> instance that can be used to track the observable.

Type Parameters
Name Description
T

Type of the operation result.

Exceptions
Type Condition
ArgumentNullException

Thrown if the observable reference is null.

| Improve this Doc View Source

FromResult<T>(T)

Creates a IAsyncOperation<TResult> that has completed with a specified result.

Declaration
public static AsyncResult<T> FromResult<T>(T result)
Parameters
Type Name Description
T result

The result value with which to complete the operation.

Returns
Type Description
AsyncResult<T>

A completed operation with the specified result value.

Type Parameters
Name Description
T
See Also
FromResult<T>(T, Object)
FromCanceled<T>()
FromException<T>(Exception)
| Improve this Doc View Source

FromResult<T>(T, Object)

Creates a IAsyncOperation<TResult> that has completed with a specified result.

Declaration
public static AsyncResult<T> FromResult<T>(T result, object asyncState)
Parameters
Type Name Description
T result

The result value with which to complete the operation.

Object asyncState

User-defined data returned by AsyncState.

Returns
Type Description
AsyncResult<T>

A completed operation with the specified result value.

Type Parameters
Name Description
T
See Also
FromResult<T>(T)
FromCanceled<T>(Object)
FromException<T>(Exception)
| Improve this Doc View Source

FromTask(Task)

Creates an IAsyncOperation instance that completes when the specified task completes.

Declaration
public static AsyncResult FromTask(Task task)
Parameters
Type Name Description
Task task

The source Task instance.

Returns
Type Description
AsyncResult

An IAsyncOperation that represents the source task.

Exceptions
Type Condition
ArgumentNullException

Thrown if the task reference is null.

See Also
FromTask<T>(Task<T>)
| Improve this Doc View Source

FromTask<T>(Task<T>)

Creates an IAsyncOperation<TResult> instance that completes when the specified task completes.

Declaration
public static AsyncResult<T> FromTask<T>(Task<T> task)
Parameters
Type Name Description
System.Threading.Tasks.Task<T> task

The source System.Threading.Tasks.Task<TResult> instance.

Returns
Type Description
AsyncResult<T>

An IAsyncOperation that represents the source task.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown if the task reference is null.

See Also
FromTask(Task)
| Improve this Doc View Source

GetNewId()

Gets a unique ID for an AsyncResult instance.

Declaration
public static int GetNewId()
Returns
Type Description
Int32
Remarks

This method should be used by all IAsyncOperation implementation for generating value of the Id property.

| Improve this Doc View Source

GetProgress()

Called when the progress is requested. Default implementation returns 0.

Declaration
protected virtual float GetProgress()
Returns
Type Description
Single
Remarks

Make sure that each method call returns a value greater or equal to the previous. It is important for progress reporting consistency.

See Also
Progress
OnProgressChanged()
TryReportProgress()
| Improve this Doc View Source

Invoke(IAsyncOperation)

Invokes the operation-specific continuation logic. Default implementation attempts to run the operation is op has succeeded; otherwise the operation transitions to failed state.

Declaration
public virtual void Invoke(IAsyncOperation op)
Parameters
Type Name Description
IAsyncOperation op

The completed antecedent operation.

| Improve this Doc View Source

OnCancel()

Called when the operation cancellation has been requested. Default implementation does nothing.

Declaration
protected virtual void OnCancel()
See Also
Cancel()
| Improve this Doc View Source

OnCompleted()

Called when the operation is completed. Default implementation does nothing.

Declaration
protected virtual void OnCompleted()
Remarks

Throwing an exception in this method results in unspecified behaviour.

See Also
OnStarted()
Status
TrySetCanceled(Boolean)
TrySetCompleted(Boolean)
TrySetException(Exception, Boolean)
| Improve this Doc View Source

OnProgressChanged()

Called when the progress value has changed. Default implementation does nothing.

Declaration
protected virtual void OnProgressChanged()
Remarks

Throwing an exception in this method results in unspecified behaviour.

See Also
Progress
GetProgress()
TryReportProgress()
| Improve this Doc View Source

OnStarted()

Called when the operation is started (Status is set to Running). Default implementation does nothing.

Declaration
protected virtual void OnStarted()
See Also
OnCompleted()
Status
Start()
TryStart()
TrySetRunning()
| Improve this Doc View Source

OnStatusChanged(AsyncOperationStatus)

Called when the operation state has changed. Default implementation does nothing.

Declaration
protected virtual void OnStatusChanged(AsyncOperationStatus status)
Parameters
Type Name Description
AsyncOperationStatus status

The new status value.

Remarks

Throwing an exception in this method results in unspecified behaviour.

See Also
Status
TrySetScheduled()
TrySetRunning()
TrySetCanceled(Boolean)
TrySetCompleted(Boolean)
TrySetException(Exception, Boolean)
| Improve this Doc View Source

RemoveCallback(Object)

Removes an existing completion/progress callback.

Declaration
public bool RemoveCallback(object action)
Parameters
Type Name Description
Object action

The callback to remove. Can be null.

Returns
Type Description
Boolean

Returns true if action was removed; false otherwise.

See Also
AddCompletionCallback(Object, SynchronizationContext)
AddProgressCallback(Object, SynchronizationContext)
| Improve this Doc View Source

Retry(Func<IAsyncOperation>, Int32)

Creates an operation that completes when the source operation is completed successfully.

Declaration
public static AsyncResult Retry(Func<IAsyncOperation> opFactory, int millisecondsRetryDelay)
Parameters
Type Name Description
System.Func<IAsyncOperation> opFactory

A delegate that initiates the source operation.

Int32 millisecondsRetryDelay

The number of milliseconds to wait after a failed try before starting a new operation.

Returns
Type Description
AsyncResult

An operation that represents the retry process.

Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory is null.

ArgumentOutOfRangeException

Thrown if millisecondsRetryDelay is less than zero.

See Also
Retry(Func<IAsyncOperation>, TimeSpan, Int32)
| Improve this Doc View Source

Retry(Func<IAsyncOperation>, Int32, Int32)

Creates an operation that completes when the source operation is completed successfully or maximum number of retries exceeded.

Declaration
public static AsyncResult Retry(Func<IAsyncOperation> opFactory, int millisecondsRetryDelay, int maxRetryCount)
Parameters
Type Name Description
System.Func<IAsyncOperation> opFactory

A delegate that initiates the source operation.

Int32 millisecondsRetryDelay

The number of milliseconds to wait after a failed try before starting a new operation.

Int32 maxRetryCount

Maximum number of retries. Zero means no limits.

Returns
Type Description
AsyncResult

An operation that represents the retry process.

Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory is null.

ArgumentOutOfRangeException

Thrown if millisecondsRetryDelay or maxRetryCount is less than zero.

See Also
Retry(Func<IAsyncOperation>, TimeSpan, Int32)
| Improve this Doc View Source

Retry(Func<IAsyncOperation>, Int32, Int32, IAsyncUpdateSource)

Creates an operation that completes when the source operation is completed successfully or maximum number of retries exceeded.

Declaration
public static AsyncResult Retry(Func<IAsyncOperation> opFactory, int millisecondsRetryDelay, int maxRetryCount, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
System.Func<IAsyncOperation> opFactory

A delegate that initiates the source operation.

Int32 millisecondsRetryDelay

The number of milliseconds to wait after a failed try before starting a new operation.

Int32 maxRetryCount

Maximum number of retries. Zero means no limits.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult

An operation that represents the retry process.

Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory or updateSource is null.

ArgumentOutOfRangeException

Thrown if millisecondsRetryDelay or maxRetryCount is less than zero.

See Also
Retry(Func<IAsyncOperation>, TimeSpan, Int32, IAsyncUpdateSource)
| Improve this Doc View Source

Retry(Func<IAsyncOperation>, Int32, IAsyncUpdateSource)

Creates an operation that completes when the source operation is completed successfully.

Declaration
public static AsyncResult Retry(Func<IAsyncOperation> opFactory, int millisecondsRetryDelay, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
System.Func<IAsyncOperation> opFactory

A delegate that initiates the source operation.

Int32 millisecondsRetryDelay

The number of milliseconds to wait after a failed try before starting a new operation.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult

An operation that represents the retry process.

Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory is null.

ArgumentOutOfRangeException

Thrown if millisecondsRetryDelay is less than zero.

See Also
Retry(Func<IAsyncOperation>, TimeSpan, Int32, IAsyncUpdateSource)
| Improve this Doc View Source

Retry(Func<IAsyncOperation>, TimeSpan)

Creates an operation that completes when the source operation is completed successfully.

Declaration
public static AsyncResult Retry(Func<IAsyncOperation> opFactory, TimeSpan retryDelay)
Parameters
Type Name Description
System.Func<IAsyncOperation> opFactory

A delegate that initiates the source operation.

TimeSpan retryDelay

The time to wait after a failed try before starting a new operation.

Returns
Type Description
AsyncResult

An operation that represents the retry process.

Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory is null.

ArgumentOutOfRangeException

Thrown if retryDelay is less than zero.

See Also
Retry(Func<IAsyncOperation>, Int32, Int32)
| Improve this Doc View Source

Retry(Func<IAsyncOperation>, TimeSpan, Int32)

Creates an operation that completes when the source operation is completed successfully or maximum number of retries exceeded.

Declaration
public static AsyncResult Retry(Func<IAsyncOperation> opFactory, TimeSpan retryDelay, int maxRetryCount)
Parameters
Type Name Description
System.Func<IAsyncOperation> opFactory

A delegate that initiates the source operation.

TimeSpan retryDelay

The time to wait after a failed try before starting a new operation.

Int32 maxRetryCount

Maximum number of retries. Zero means no limits.

Returns
Type Description
AsyncResult

An operation that represents the retry process.

Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory is null.

ArgumentOutOfRangeException

Thrown if retryDelay or maxRetryCount is less than zero.

See Also
Retry(Func<IAsyncOperation>, Int32, Int32)
| Improve this Doc View Source

Retry(Func<IAsyncOperation>, TimeSpan, Int32, IAsyncUpdateSource)

Creates an operation that completes when the source operation is completed successfully or maximum number of retries exceeded.

Declaration
public static AsyncResult Retry(Func<IAsyncOperation> opFactory, TimeSpan retryDelay, int maxRetryCount, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
System.Func<IAsyncOperation> opFactory

A delegate that initiates the source operation.

TimeSpan retryDelay

The time to wait after a failed try before starting a new operation.

Int32 maxRetryCount

Maximum number of retries. Zero means no limits.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult

An operation that represents the retry process.

Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory or updateSource is null.

ArgumentOutOfRangeException

Thrown if retryDelay or maxRetryCount is less than zero.

See Also
Retry(Func<IAsyncOperation>, Int32, Int32, IAsyncUpdateSource)
| Improve this Doc View Source

Retry(Func<IAsyncOperation>, TimeSpan, IAsyncUpdateSource)

Creates an operation that completes when the source operation is completed successfully.

Declaration
public static AsyncResult Retry(Func<IAsyncOperation> opFactory, TimeSpan retryDelay, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
System.Func<IAsyncOperation> opFactory

A delegate that initiates the source operation.

TimeSpan retryDelay

The time to wait after a failed try before starting a new operation.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult

An operation that represents the retry process.

Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory or updateSource is null.

ArgumentOutOfRangeException

Thrown if retryDelay is less than zero.

See Also
Retry(Func<IAsyncOperation>, Int32, Int32, IAsyncUpdateSource)
| Improve this Doc View Source

Retry<TResult>(Func<IAsyncOperation<TResult>>, Int32)

Creates an operation that completes when the source operation is completed successfully.

Declaration
public static AsyncResult<TResult> Retry<TResult>(Func<IAsyncOperation<TResult>> opFactory, int millisecondsRetryDelay)
Parameters
Type Name Description
System.Func<IAsyncOperation<TResult>> opFactory

A delegate that initiates the source operation.

Int32 millisecondsRetryDelay

The number of milliseconds to wait after a failed try before starting a new operation.

Returns
Type Description
AsyncResult<TResult>

An operation that represents the retry process.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory is null.

ArgumentOutOfRangeException

Thrown if millisecondsRetryDelay is less than zero.

See Also
Retry<TResult>(Func<IAsyncOperation<TResult>>, TimeSpan, Int32)
| Improve this Doc View Source

Retry<TResult>(Func<IAsyncOperation<TResult>>, Int32, Int32)

Creates an operation that completes when the source operation is completed successfully or maximum number of retries exceeded.

Declaration
public static AsyncResult<TResult> Retry<TResult>(Func<IAsyncOperation<TResult>> opFactory, int millisecondsRetryDelay, int maxRetryCount)
Parameters
Type Name Description
System.Func<IAsyncOperation<TResult>> opFactory

A delegate that initiates the source operation.

Int32 millisecondsRetryDelay

The number of milliseconds to wait after a failed try before starting a new operation.

Int32 maxRetryCount

Maximum number of retries. Zero means no limits.

Returns
Type Description
AsyncResult<TResult>

An operation that represents the retry process.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory is null.

ArgumentOutOfRangeException

Thrown if millisecondsRetryDelay or maxRetryCount is less than zero.

See Also
Retry<TResult>(Func<IAsyncOperation<TResult>>, TimeSpan, Int32)
| Improve this Doc View Source

Retry<TResult>(Func<IAsyncOperation<TResult>>, Int32, Int32, IAsyncUpdateSource)

Creates an operation that completes when the source operation is completed successfully or maximum number of retries exceeded.

Declaration
public static AsyncResult<TResult> Retry<TResult>(Func<IAsyncOperation<TResult>> opFactory, int millisecondsRetryDelay, int maxRetryCount, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
System.Func<IAsyncOperation<TResult>> opFactory

A delegate that initiates the source operation.

Int32 millisecondsRetryDelay

The number of milliseconds to wait after a failed try before starting a new operation.

Int32 maxRetryCount

Maximum number of retries. Zero means no limits.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult<TResult>

An operation that represents the retry process.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory or updateSource is null.

ArgumentOutOfRangeException

Thrown if millisecondsRetryDelay or maxRetryCount is less than zero.

See Also
Retry<TResult>(Func<IAsyncOperation<TResult>>, TimeSpan, Int32, IAsyncUpdateSource)
| Improve this Doc View Source

Retry<TResult>(Func<IAsyncOperation<TResult>>, Int32, IAsyncUpdateSource)

Creates an operation that completes when the source operation is completed successfully.

Declaration
public static AsyncResult<TResult> Retry<TResult>(Func<IAsyncOperation<TResult>> opFactory, int millisecondsRetryDelay, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
System.Func<IAsyncOperation<TResult>> opFactory

A delegate that initiates the source operation.

Int32 millisecondsRetryDelay

The number of milliseconds to wait after a failed try before starting a new operation.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult<TResult>

An operation that represents the retry process.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory or updateSource is null.

ArgumentOutOfRangeException

Thrown if millisecondsRetryDelay is less than zero.

See Also
Retry<TResult>(Func<IAsyncOperation<TResult>>, TimeSpan, Int32, IAsyncUpdateSource)
| Improve this Doc View Source

Retry<TResult>(Func<IAsyncOperation<TResult>>, TimeSpan)

Creates an operation that completes when the source operation is completed successfully.

Declaration
public static AsyncResult<TResult> Retry<TResult>(Func<IAsyncOperation<TResult>> opFactory, TimeSpan retryDelay)
Parameters
Type Name Description
System.Func<IAsyncOperation<TResult>> opFactory

A delegate that initiates the source operation.

TimeSpan retryDelay

The time to wait after a failed try before starting a new operation.

Returns
Type Description
AsyncResult<TResult>

An operation that represents the retry process.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory is null.

ArgumentOutOfRangeException

Thrown if retryDelay is less than zero.

See Also
Retry<TResult>(Func<IAsyncOperation<TResult>>, Int32, Int32)
| Improve this Doc View Source

Retry<TResult>(Func<IAsyncOperation<TResult>>, TimeSpan, Int32)

Creates an operation that completes when the source operation is completed successfully or maximum number of retries exceeded.

Declaration
public static AsyncResult<TResult> Retry<TResult>(Func<IAsyncOperation<TResult>> opFactory, TimeSpan retryDelay, int maxRetryCount)
Parameters
Type Name Description
System.Func<IAsyncOperation<TResult>> opFactory

A delegate that initiates the source operation.

TimeSpan retryDelay

The time to wait after a failed try before starting a new operation.

Int32 maxRetryCount

Maximum number of retries. Zero means no limits.

Returns
Type Description
AsyncResult<TResult>

An operation that represents the retry process.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory is null.

ArgumentOutOfRangeException

Thrown if retryDelay or maxRetryCount is less than zero.

See Also
Retry<TResult>(Func<IAsyncOperation<TResult>>, Int32, Int32)
| Improve this Doc View Source

Retry<TResult>(Func<IAsyncOperation<TResult>>, TimeSpan, Int32, IAsyncUpdateSource)

Creates an operation that completes when the source operation is completed successfully or maximum number of retries exceeded.

Declaration
public static AsyncResult<TResult> Retry<TResult>(Func<IAsyncOperation<TResult>> opFactory, TimeSpan retryDelay, int maxRetryCount, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
System.Func<IAsyncOperation<TResult>> opFactory

A delegate that initiates the source operation.

TimeSpan retryDelay

The time to wait after a failed try before starting a new operation.

Int32 maxRetryCount

Maximum number of retries. Zero means no limits.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult<TResult>

An operation that represents the retry process.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory or updateSource is null.

ArgumentOutOfRangeException

Thrown if retryDelay or maxRetryCount is less than zero.

See Also
Retry<TResult>(Func<IAsyncOperation<TResult>>, Int32, Int32, IAsyncUpdateSource)
| Improve this Doc View Source

Retry<TResult>(Func<IAsyncOperation<TResult>>, TimeSpan, IAsyncUpdateSource)

Creates an operation that completes when the source operation is completed successfully.

Declaration
public static AsyncResult<TResult> Retry<TResult>(Func<IAsyncOperation<TResult>> opFactory, TimeSpan retryDelay, IAsyncUpdateSource updateSource)
Parameters
Type Name Description
System.Func<IAsyncOperation<TResult>> opFactory

A delegate that initiates the source operation.

TimeSpan retryDelay

The time to wait after a failed try before starting a new operation.

IAsyncUpdateSource updateSource

Update notifications provider.

Returns
Type Description
AsyncResult<TResult>

An operation that represents the retry process.

Type Parameters
Name Description
TResult
Exceptions
Type Condition
ArgumentNullException

Thrown if the opFactory or updateSource is null.

ArgumentOutOfRangeException

Thrown if retryDelay is less than zero.

See Also
Retry<TResult>(Func<IAsyncOperation<TResult>>, Int32, Int32, IAsyncUpdateSource)
| Improve this Doc View Source

Start()

Transitions the operation into the Running state.

Declaration
public void Start()
Remarks

An operation may be started on once. Any attempts to schedule it a second time will result in an exception.

The Start() is used to execute an operation that has been created by calling one of the constructors. Typically, you do this when you need to separate the operation's creation from its execution, such as when you conditionally execute operations that you've created.

Exceptions
Type Condition
InvalidOperationException

Thrown if the transition has failed.

ObjectDisposedException

Thrown is the operation is disposed.

See Also
TryStart()
TrySetRunning()
OnStarted()
| Improve this Doc View Source

ThrowIfDisposed()

Throws ObjectDisposedException if this operation has been disposed.

Declaration
protected void ThrowIfDisposed()
| Improve this Doc View Source

ThrowIfNonSuccess()

Throws exception if the operation has failed or canceled.

Declaration
protected void ThrowIfNonSuccess()
| Improve this Doc View Source

TryReportProgress()

Reports changes in operation progress value.

Declaration
protected bool TryReportProgress()
Returns
Type Description
Boolean

Returns true if the attemp was successfull; false otherwise.

| Improve this Doc View Source

TrySetCanceled()

Attempts to transition the operation into the Canceled state.

Declaration
protected bool TrySetCanceled()
Returns
Type Description
Boolean

Returns true if the attemp was successfull; false otherwise.

Exceptions
Type Condition
ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetCanceled(Boolean)
| Improve this Doc View Source

TrySetCanceled(Boolean)

Attempts to transition the operation into the Canceled state.

Declaration
protected bool TrySetCanceled(bool completedSynchronously)
Parameters
Type Name Description
Boolean completedSynchronously

Value of the CompletedSynchronously property.

Returns
Type Description
Boolean

Returns true if the attemp was successfull; false otherwise.

Exceptions
Type Condition
ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetCanceled()
| Improve this Doc View Source

TrySetCompleted()

Attempts to transition the operation into the RanToCompletion state.

Declaration
protected bool TrySetCompleted()
Returns
Type Description
Boolean

Returns true if the attemp was successfull; false otherwise.

Exceptions
Type Condition
ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetCompleted(Boolean)
| Improve this Doc View Source

TrySetCompleted(Boolean)

Attempts to transition the operation into the RanToCompletion state.

Declaration
protected bool TrySetCompleted(bool completedSynchronously)
Parameters
Type Name Description
Boolean completedSynchronously

Value of the CompletedSynchronously property.

Returns
Type Description
Boolean

Returns true if the attemp was successfull; false otherwise.

Exceptions
Type Condition
ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetCompleted()
| Improve this Doc View Source

TrySetException(Exception)

Attempts to transition the operation into the Faulted (or Canceled if the exception is OperationCanceledException) state.

Declaration
protected bool TrySetException(Exception exception)
Parameters
Type Name Description
Exception exception

An exception that caused the operation to end prematurely.

Returns
Type Description
Boolean

Returns true if the attemp was successfull; false otherwise.

Exceptions
Type Condition
ArgumentNullException

Thrown if exception is null.

ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetException(Exception, Boolean)
| Improve this Doc View Source

TrySetException(Exception, Boolean)

Attempts to transition the operation into the Faulted (or Canceled if the exception is OperationCanceledException) state.

Declaration
protected bool TrySetException(Exception exception, bool completedSynchronously)
Parameters
Type Name Description
Exception exception

An exception that caused the operation to end prematurely.

Boolean completedSynchronously

Value of the CompletedSynchronously property.

Returns
Type Description
Boolean

Returns true if the attemp was successfull; false otherwise.

Exceptions
Type Condition
ArgumentNullException

Thrown if exception is null.

ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetException(Exception)
| Improve this Doc View Source

TrySetException(String)

Attempts to transition the operation into the Faulted. The method calls TrySetException(Exception) passing a new Exception instance with the specified message.

Declaration
protected bool TrySetException(string message)
Parameters
Type Name Description
String message

An exception message.

Returns
Type Description
Boolean

Returns true if the attemp was successfull; false otherwise.

Exceptions
Type Condition
ArgumentNullException

Thrown if message is null.

ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetException(Exception)
| Improve this Doc View Source

TrySetException(String, Boolean)

Attempts to transition the operation into the Faulted. The method calls TrySetException(Exception, Boolean) passing a new Exception instance with the specified message.

Declaration
protected bool TrySetException(string message, bool completedSynchronously)
Parameters
Type Name Description
String message

An exception message.

Boolean completedSynchronously

Value of the CompletedSynchronously property.

Returns
Type Description
Boolean

Returns true if the attemp was successfull; false otherwise.

Exceptions
Type Condition
ArgumentNullException

Thrown if message is null.

ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetException(Exception, Boolean)
| Improve this Doc View Source

TrySetRunning()

Attempts to transition the operation into the Running state.

Declaration
protected bool TrySetRunning()
Returns
Type Description
Boolean
Exceptions
Type Condition
ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetScheduled()
| Improve this Doc View Source

TrySetScheduled()

Attempts to transition the operation into the Scheduled state.

Declaration
protected bool TrySetScheduled()
Returns
Type Description
Boolean
Exceptions
Type Condition
ObjectDisposedException

Thrown is the operation is disposed.

See Also
TrySetRunning()
| Improve this Doc View Source

TryStart()

Attempts to transitions the operation into the Running state.

Declaration
public bool TryStart()
Returns
Type Description
Boolean

Returns true if the operation status was changed to Running; false otherwise.

Exceptions
Type Condition
ObjectDisposedException

Thrown is the operation is disposed.

See Also
Start()
TrySetRunning()
OnStarted()
| Improve this Doc View Source

WhenAll(IEnumerable<IAsyncOperation>)

Creates an operation that will complete when all of the specified objects in an enumerable collection have completed.

Declaration
public static AsyncResult WhenAll(IEnumerable<IAsyncOperation> ops)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<IAsyncOperation> ops

The operations to wait on for completion.

Returns
Type Description
AsyncResult

An operation that represents the completion of all of the supplied operations.

Exceptions
Type Condition
ArgumentNullException

Thrown if ops is null.

ArgumentException

Thrown if the ops collection contained a null operation..

See Also
WhenAll<T>(IEnumerable<IAsyncOperation<T>>)
WhenAll(IAsyncOperation[])
| Improve this Doc View Source

WhenAll(IAsyncOperation[])

Creates an operation that will complete when all of the specified objects in an array have completed.

Declaration
public static AsyncResult WhenAll(params IAsyncOperation[] ops)
Parameters
Type Name Description
IAsyncOperation[] ops

The operations to wait on for completion.

Returns
Type Description
AsyncResult

An operation that represents the completion of all of the supplied operations.

Exceptions
Type Condition
ArgumentNullException

Thrown if ops is null.

ArgumentException

Thrown if the ops collection contained a null operation..

See Also
WhenAll<T>(IAsyncOperation<T>[])
WhenAll(IEnumerable<IAsyncOperation>)
| Improve this Doc View Source

WhenAll<T>(IEnumerable<IAsyncOperation<T>>)

Creates an operation that will complete when all of the specified objects in an enumerable collection have completed.

Declaration
public static AsyncResult<T[]> WhenAll<T>(IEnumerable<IAsyncOperation<T>> ops)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<IAsyncOperation<T>> ops

The operations to wait on for completion.

Returns
Type Description
AsyncResult<T[]>

An operation that represents the completion of all of the supplied operations.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown if ops is null.

ArgumentException

Thrown if the ops collection contained a null operation..

See Also
WhenAll(IEnumerable<IAsyncOperation>)
WhenAll<T>(IAsyncOperation<T>[])
| Improve this Doc View Source

WhenAll<T>(IAsyncOperation<T>[])

Creates an operation that will complete when all of the specified objects in an array have completed.

Declaration
public static AsyncResult<T[]> WhenAll<T>(params IAsyncOperation<T>[] ops)
Parameters
Type Name Description
IAsyncOperation<T>[] ops

The operations to wait on for completion.

Returns
Type Description
AsyncResult<T[]>

An operation that represents the completion of all of the supplied operations.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown if ops is null.

ArgumentException

Thrown if the ops collection contained a null operation.

See Also
WhenAll(IAsyncOperation[])
WhenAll<T>(IEnumerable<IAsyncOperation<T>>)
| Improve this Doc View Source

WhenAny<T>(T[])

Creates an operation that will complete when any of the specified objects in an array have completed.

Declaration
public static AsyncResult<T> WhenAny<T>(params T[] ops)where T : IAsyncOperation
Parameters
Type Name Description
T[] ops

The operations to wait on for completion.

Returns
Type Description
AsyncResult<T>

An operation that represents the completion of any of the supplied operations.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown if ops is null.

ArgumentException

Thrown if the ops collection contained a null operation..

See Also
WhenAny<T>(IEnumerable<T>)
| Improve this Doc View Source

WhenAny<T>(IEnumerable<T>)

Creates an operation that will complete when any of the specified objects in an enumerable collection have completed.

Declaration
public static AsyncResult<T> WhenAny<T>(IEnumerable<T> ops)where T : IAsyncOperation
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> ops

The operations to wait on for completion.

Returns
Type Description
AsyncResult<T>

An operation that represents the completion of any of the supplied operations.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown if ops is null.

ArgumentException

Thrown if the ops collection contained a null operation..

See Also
WhenAny<T>(T[])
| Improve this Doc View Source

Yield()

Creates an awaitable that asynchronously yields back to the current context when awaited (works the same as Yield()).

Declaration
public static YieldAwaitable Yield()
Returns
Type Description
YieldAwaitable

A context that, when awaited, will asynchronously transition back into the current context at the time of the await. If the current SynchronizationContext is non-null, that is treated as the current context. Otherwise, the continuation is executed on the ThreadPool.

Events

| Improve this Doc View Source

Completed

Raised when the operation is completed.

Declaration
public event AsyncCompletedEventHandler Completed
Event Type
Type Description
AsyncCompletedEventHandler
Remarks

The event handler is invoked on a thread that registered it (if it has a SynchronizationContext attached). If the operation is already completed the event handler is called synchronously. Throwing an exception from the event handler might cause unspecified behaviour.

Exceptions
Type Condition
ArgumentNullException

Thrown if the delegate being registered is null.

ObjectDisposedException

Thrown is the operation has been disposed.

See Also
ProgressChanged
| Improve this Doc View Source

ProgressChanged

Raised when the operation progress is changed.

Declaration
public event ProgressChangedEventHandler ProgressChanged
Event Type
Type Description
ProgressChangedEventHandler
Remarks

The event handler is invoked on a thread that registered it (if it has a SynchronizationContext attached). If the operation is already completed the event handler is called synchronously. Throwing an exception from the event handler might cause unspecified behaviour.

Exceptions
Type Condition
ArgumentNullException

Thrown if the delegate being registered is null.

ObjectDisposedException

Thrown is the operation has been disposed.

See Also
Completed

Explicit Interface Implementations

| Improve this Doc View Source

IEnumerator.Current

Gets the current element in the collection.

Declaration
object IEnumerator.Current { get; }
Returns
Type Description
Object

The current element in the collection.

Remarks

Not implemented. Always returns null.

| Improve this Doc View Source

IEnumerator.MoveNext()

Advances the enumerator to the next element of the collection.

Declaration
bool IEnumerator.MoveNext()
Returns
Type Description
Boolean

Returns true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.

Remarks

Checks whether the operation is completed. Returns false if it is; otherwise, true.

| Improve this Doc View Source

IEnumerator.Reset()

Sets the enumerator to its initial position, which is before the first element in the collection.

Declaration
void IEnumerator.Reset()
Remarks

Not implemented. Always throws NotSupportedException.

Implements

IAsyncOperation
IAsyncOperationCallbacks
IAsyncCancellable
System.IAsyncResult
System.IDisposable
IAsyncContinuation
System.Collections.IEnumerator

Extension Methods

AsyncExtensions.ThrowIfNonSuccess(IAsyncOperation)
AsyncExtensions.WithCancellation(IAsyncOperation, CancellationToken)
AsyncExtensions.Wait(IAsyncOperation)
AsyncExtensions.Wait(IAsyncOperation, Int32)
AsyncExtensions.Wait(IAsyncOperation, TimeSpan)
AsyncExtensions.Wait(IAsyncOperation, CancellationToken)
AsyncExtensions.Wait(IAsyncOperation, Int32, CancellationToken)
AsyncExtensions.Wait(IAsyncOperation, TimeSpan, CancellationToken)
AsyncExtensions.Join(IAsyncOperation)
AsyncExtensions.Join(IAsyncOperation, Int32)
AsyncExtensions.Join(IAsyncOperation, TimeSpan)
AsyncExtensions.Join(IAsyncOperation, CancellationToken)
AsyncExtensions.Join(IAsyncOperation, Int32, CancellationToken)
AsyncExtensions.Join(IAsyncOperation, TimeSpan, CancellationToken)
AsyncExtensions.ContinueWith(IAsyncOperation, Action<IAsyncOperation>)
AsyncExtensions.ContinueWith(IAsyncOperation, Action<IAsyncOperation>, AsyncContinuationOptions)
AsyncExtensions.ContinueWith(IAsyncOperation, Action<IAsyncOperation, Object>, Object)
AsyncExtensions.ContinueWith(IAsyncOperation, Action<IAsyncOperation, Object>, Object, AsyncContinuationOptions)
AsyncExtensions.ContinueWith<TResult>(IAsyncOperation, Func<IAsyncOperation, TResult>)
AsyncExtensions.ContinueWith<TResult>(IAsyncOperation, Func<IAsyncOperation, TResult>, AsyncContinuationOptions)
AsyncExtensions.ContinueWith<TResult>(IAsyncOperation, Func<IAsyncOperation, Object, TResult>, Object)
AsyncExtensions.ContinueWith<TResult>(IAsyncOperation, Func<IAsyncOperation, Object, TResult>, Object, AsyncContinuationOptions)
AsyncExtensions.ToTask(IAsyncOperation)
AsyncExtensions.GetAwaiter(IAsyncOperation)
AsyncExtensions.ConfigureAwait(IAsyncOperation, Boolean)
AsyncExtensions.ConfigureAwait(IAsyncOperation, AsyncCallbackOptions)
AsyncExtensions.AddCompletionCallback(IAsyncOperationCallbacks, Action)
AsyncExtensions.AddCompletionCallback(IAsyncOperationCallbacks, Action, AsyncCallbackOptions)
AsyncExtensions.AddCompletionCallback(IAsyncOperationCallbacks, Action<IAsyncOperation>)
AsyncExtensions.AddCompletionCallback(IAsyncOperationCallbacks, Action<IAsyncOperation>, AsyncCallbackOptions)
AsyncExtensions.AddCompletionCallback(IAsyncOperationCallbacks, IAsyncContinuation)
AsyncExtensions.AddCompletionCallback(IAsyncOperationCallbacks, IAsyncContinuation, AsyncCallbackOptions)
AsyncExtensions.AddProgressCallback(IAsyncOperationCallbacks, Action<Single>)
AsyncExtensions.AddProgressCallback(IAsyncOperationCallbacks, Action<Single>, AsyncCallbackOptions)
AsyncExtensions.AddProgressCallback(IAsyncOperationCallbacks, IProgress<Single>)
AsyncExtensions.AddProgressCallback(IAsyncOperationCallbacks, IProgress<Single>, AsyncCallbackOptions)
IAsyncResultExtensions.ToEnum(IAsyncResult)
IAsyncResultExtensions.SpinUntilCompleted(IAsyncResult)
IAsyncResultExtensions.SpinUntilCompleted(IAsyncResult, Int32)
IAsyncResultExtensions.SpinUntilCompleted(IAsyncResult, TimeSpan)
IAsyncResultExtensions.SpinUntilCompleted(IAsyncResult, CancellationToken)
IAsyncResultExtensions.SpinUntilCompleted(IAsyncResult, Int32, CancellationToken)
IAsyncResultExtensions.SpinUntilCompleted(IAsyncResult, TimeSpan, CancellationToken)
PromiseExtensions.Then(IAsyncOperation, Action)
PromiseExtensions.Then(IAsyncOperation, Func<IAsyncOperation>)
PromiseExtensions.Then<TResult>(IAsyncOperation, Func<IAsyncOperation<TResult>>)
PromiseExtensions.Then(IAsyncOperation, Action, Action<Exception>)
PromiseExtensions.Then(IAsyncOperation, Func<IAsyncOperation>, Action<Exception>)
PromiseExtensions.ThenAll(IAsyncOperation, Func<IEnumerable<IAsyncOperation>>)
PromiseExtensions.ThenAll<T>(IAsyncOperation, Func<IEnumerable<IAsyncOperation<T>>>)
PromiseExtensions.ThenAny(IAsyncOperation, Func<IEnumerable<IAsyncOperation>>)
PromiseExtensions.ThenAny<TResult>(IAsyncOperation, Func<IEnumerable<IAsyncOperation<TResult>>>)
PromiseExtensions.ThenSequence(IAsyncOperation, Func<IEnumerable<Func<IAsyncOperation>>>)
PromiseExtensions.ThenSequence(IAsyncOperation, Func<Func<IAsyncOperation>[]>)
PromiseExtensions.Rebind<TResult>(IAsyncOperation, Func<TResult>)
PromiseExtensions.Catch(IAsyncOperation, Action<Exception>)
PromiseExtensions.Catch<TException>(IAsyncOperation, Action<TException>)
PromiseExtensions.Finally(IAsyncOperation, Action)
PromiseExtensions.Done(IAsyncOperation, Action)
PromiseExtensions.Done(IAsyncOperation, Action, Action<Exception>)
PromiseExtensions.Done(IAsyncOperation)

See Also

Promises for game development
How to implement the IAsyncResult design pattern
Task-based Asynchronous Pattern (TAP)
Asynchronous Programming Model (APM)
Task
TaskCompletionSource
AsyncCompletionSource
AsyncResult<TResult>
IAsyncResult
  • Improve this Doc
  • View Source
Back to top Copyright (c) 2017-2018 Alexander Bogarsukov