Class AsyncResult
A lightweight net35
-compatible asynchronous operation (promise) for Unity3d
.
Implements
Inherited Members
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 SourceAsyncResult()
Initializes a new instance of the AsyncResult class.
Declaration
public AsyncResult()
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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 SourceAsyncState
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. |
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
| Improve this Doc View SourceCanceledOperation
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.
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.
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
| Improve this Doc View SourceCreationOptions
Gets the AsyncCreationOptions used to create this operation.
Declaration
public AsyncCreationOptions CreationOptions { get; }
Property Value
Type | Description |
---|---|
AsyncCreationOptions | The operation creation options. |
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.
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. |
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.
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. |
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. |
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. |
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
| Improve this Doc View SourceIsCompletedSuccessfully
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. |
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. |
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. |
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. |
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. |
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]. |
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 SourceAddCompletionCallback(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 |
ObjectDisposedException | Thrown is the operation has been disposed. |
See Also
| Improve this Doc View SourceAddProgressCallback(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 |
ObjectDisposedException | Thrown is the operation has been disposed. |
See Also
| Improve this Doc View SourceCancel()
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.
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 |
See Also
| Improve this Doc View SourceDelay(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 |
ArgumentOutOfRangeException | Thrown if the |
See Also
| Improve this Doc View SourceDelay(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 |
See Also
| Improve this Doc View SourceDelay(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 |
ArgumentOutOfRangeException | Thrown if the |
See Also
| Improve this Doc View SourceDelay(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 |
Returns
Type | Description |
---|---|
AsyncResult | An operation that represents the time delay. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if the |
See Also
| Improve this Doc View SourceDelay(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 |
IAsyncUpdateSource | updateSource | Update notifications provider. |
Returns
Type | Description |
---|---|
AsyncResult | An operation that represents the time delay. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
ArgumentOutOfRangeException | Thrown if the |
See Also
| Improve this Doc View SourceDispose()
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
| Improve this Doc View SourceDispose(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
| Improve this Doc View SourceFromAction(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 |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
See Also
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 |
Returns
Type | Description |
---|---|
AsyncResult | A completed operation that represents |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
See Also
| Improve this Doc View SourceFromAction(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 |
Returns
Type | Description |
---|---|
AsyncResult<Object> | A completed operation that represents the |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
See Also
| Improve this Doc View SourceFromAction(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 |
Returns
Type | Description |
---|---|
AsyncResult | A completed operation that represents |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
See Also
| Improve this Doc View SourceFromAction<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 |
Returns
Type | Description |
---|---|
AsyncResult | A completed operation that represents |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
See Also
| Improve this Doc View SourceFromAction<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 |
Type Parameters
Name | Description |
---|---|
TResult |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
See Also
| Improve this Doc View SourceFromAction<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 |
Returns
Type | Description |
---|---|
AsyncResult<TResult> | A completed operation that represents |
Type Parameters
Name | Description |
---|---|
TResult |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
See Also
| Improve this Doc View SourceFromAction<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 |
Returns
Type | Description |
---|---|
AsyncResult<TResult> | A completed operation that represents |
Type Parameters
Name | Description |
---|---|
T | |
TResult |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
See Also
| Improve this Doc View SourceFromCanceled()
Creates a IAsyncOperation that is canceled.
Declaration
public static AsyncResult FromCanceled()
Returns
Type | Description |
---|---|
AsyncResult | A canceled operation. |
See Also
| Improve this Doc View SourceFromCanceled(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
| Improve this Doc View SourceFromCanceled<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
| Improve this Doc View SourceFromCanceled<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
| Improve this Doc View SourceFromException(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 |
See Also
| Improve this Doc View SourceFromException(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 |
See Also
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
| Improve this Doc View SourceFromException(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
| Improve this Doc View SourceFromException<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
| Improve this Doc View SourceFromException<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<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
| Improve this Doc View SourceFromException<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
| Improve this Doc View SourceFromObservable<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 |
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
| Improve this Doc View SourceFromResult<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
| Improve this Doc View SourceFromTask(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 |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the |
See Also
| Improve this Doc View SourceFromTask<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 |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the |
See Also
| Improve this Doc View SourceGetNewId()
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.
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
| Improve this Doc View SourceInvoke(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. |
OnCancel()
Called when the operation cancellation has been requested. Default implementation does nothing.
Declaration
protected virtual void OnCancel()
See Also
| Improve this Doc View SourceOnCompleted()
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
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
| Improve this Doc View SourceOnStarted()
Called when the operation is started (Status is set to Running). Default implementation does nothing.
Declaration
protected virtual void OnStarted()
See Also
| Improve this Doc View SourceOnStatusChanged(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
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 |
See Also
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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry(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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry(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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry(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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry(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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry(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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry(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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry(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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry<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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry<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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry<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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry<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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry<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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry<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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry<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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceRetry<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 |
ArgumentOutOfRangeException | Thrown if |
See Also
| Improve this Doc View SourceStart()
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
| Improve this Doc View SourceThrowIfDisposed()
Throws ObjectDisposedException if this operation has been disposed.
Declaration
protected void ThrowIfDisposed()
ThrowIfNonSuccess()
Throws exception if the operation has failed or canceled.
Declaration
protected void ThrowIfNonSuccess()
TryReportProgress()
Reports changes in operation progress value.
Declaration
protected bool TryReportProgress()
Returns
Type | Description |
---|---|
Boolean | Returns true if the attemp was successfull; false otherwise. |
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
| Improve this Doc View SourceTrySetCanceled(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
| Improve this Doc View SourceTrySetCompleted()
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
| Improve this Doc View SourceTrySetCompleted(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
| Improve this Doc View SourceTrySetException(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 |
ObjectDisposedException | Thrown is the operation is disposed. |
See Also
| Improve this Doc View SourceTrySetException(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 |
ObjectDisposedException | Thrown is the operation is disposed. |
See Also
| Improve this Doc View SourceTrySetException(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 |
ObjectDisposedException | Thrown is the operation is disposed. |
See Also
| Improve this Doc View SourceTrySetException(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 |
ObjectDisposedException | Thrown is the operation is disposed. |
See Also
| Improve this Doc View SourceTrySetRunning()
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
| Improve this Doc View SourceTrySetScheduled()
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
| Improve this Doc View SourceTryStart()
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
| Improve this Doc View SourceWhenAll(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 |
ArgumentException | Thrown if the |
See Also
| Improve this Doc View SourceWhenAll(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 |
ArgumentException | Thrown if the |
See Also
| Improve this Doc View SourceWhenAll<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 |
ArgumentException | Thrown if the |
See Also
| Improve this Doc View SourceWhenAll<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 |
ArgumentException | Thrown if the |
See Also
| Improve this Doc View SourceWhenAny<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 |
ArgumentException | Thrown if the |
See Also
| Improve this Doc View SourceWhenAny<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 |
ArgumentException | Thrown if the |
See Also
| Improve this Doc View SourceYield()
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 SourceCompleted
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
| Improve this Doc View SourceProgressChanged
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
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerator.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.
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.
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.