Interface IAsyncRelayCommandCommon
An interface to define a reusable command that encapsulates the implementation of ICommand with support for async/await command delegates and data binding (implements INotifyPropertyChanged).
Enables instant creation of an ICommand without implementing the ICommand interface for each command.
Inherited Members
Namespace: BionicCode.Utilities.Net
Assembly: BionicCode.Utilities.Net.Common.dll
Syntax
public interface IAsyncRelayCommandCommon : ICommand, INotifyPropertyChanged
Properties
| Improve this Doc View SourceCanBeCanceled
Returns whether the command can be cancelled.
Declaration
bool CanBeCanceled { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
|
CurrentCancellationToken
The currently used CancellationToken.
Declaration
CancellationToken CurrentCancellationToken { get; }
Property Value
| Type | Description |
|---|---|
| CancellationToken | A CancellationToken instance currently in use during the command execution. |
Remarks
This property can be used to query the state of the cancellation or to register a cancellation callback by calling Register(Action).
The instance will change for each command execution.
HasPending
Return whether the command has pending executions.
Declaration
bool HasPending { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Remarks
Only one command is executed at time. Sucessive command invocations are enqueued and run after the currently executing delegate has completed
or was cancelled.
IsCancelled
Returns whether the command's executing operation was cancelled.
Declaration
bool IsCancelled { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
|
IsExecuting
A flag to signal if the asynchronous operation has completed.
Declaration
bool IsExecuting { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
IsPendingCancelled
Returns whether the command's pending operations were cancelled.
Declaration
bool IsPendingCancelled { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
|
PendingCount
Returns the number of pending command delegate executions.
Declaration
int PendingCount { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Methods
| Improve this Doc View SourceCancelAll()
Cancels all pending and executing commands.
Declaration
void CancelAll()
Remarks
See Cancel() for the exception behavior of this overload.
CancelAll(Boolean)
Cancels all pending and executing commands.
Declaration
void CancelAll(bool throwOnFirstException)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | throwOnFirstException | See Cancel(Boolean) for the effects of the parameter. |
Remarks
See Cancel(Boolean) for the exception behavior of this overload.
CancelExecuting()
Cancels the currently executing command.
Declaration
void CancelExecuting()
Remarks
See Cancel() for the exception behavior of this overload.
CancelExecuting(Boolean)
Cancels the currently executing command.
Declaration
void CancelExecuting(bool throwOnFirstException)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | throwOnFirstException | See Cancel(Boolean) for the effects of the parameter. |
Remarks
See Cancel(Boolean) for the exception behavior of this overload.
CancelPending()
Cancels all pending command executions.
Declaration
void CancelPending()
Remarks
See Cancel() for the exception behavior of this overload.
CancelPending(Boolean)
Cancels all pending command executions.
Declaration
void CancelPending(bool throwOnFirstException)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | throwOnFirstException | See Cancel(Boolean) for the effects of the parameter. |
Remarks
See Cancel(Boolean) for the exception behavior of this overload.
CanExecute()
Checks if the ICommand can execute.
Declaration
bool CanExecute()
Returns
| Type | Description |
|---|---|
| Boolean |
|
ExecuteAsync()
Executes the AsyncRelayCommand on the current command target asynchronously.
Declaration
Task ExecuteAsync()
Returns
| Type | Description |
|---|---|
| Task |
Remarks
If the registered command handler is asynchronous (awaitable), then the execution is asynchronous otherwise the delegate is executed synchronously.
ExecuteAsync(CancellationToken)
Executes the AsyncRelayCommand on the current command target asynchronously.
Declaration
Task ExecuteAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | An instance of CancellationToken to cancel the executing command delegate. |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
If the registered command handler is asynchronous (awaitable), then the execution is asynchronous otherwise the delegate is executed synchronously.
Only one command is executed at time. Sucessive command invocations are enqueued and run after the currently executing delegate has completed
or was cancelled. Query HasPending to know if the command has pending delegate executions and PendingCount to knwo the number of pending delegate executions.
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | If executing command delegate was cancelled. |
ExecuteAsync(TimeSpan)
Executes the AsyncRelayCommand on the current command target asynchronously.
Declaration
Task ExecuteAsync(TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | A TimeSpan to specify the timeout of the operation.
|
Returns
| Type | Description |
|---|---|
| Task |
Remarks
If the registered command handler is asynchronous (awaitable), then the execution is asynchronous otherwise the delegate is executed synchronously.
Only one command is executed at time. Sucessive command invocations are enqueued and run after the currently executing delegate has completed
or was cancelled. Query HasPending to know if the command has pending delegate executions and PendingCount to knwo the number of pending delegate executions.
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | If the executing command delegate was cancelled. |
ExecuteAsync(TimeSpan, CancellationToken)
Executes the AsyncRelayCommand on the current command target asynchronously.
Declaration
Task ExecuteAsync(TimeSpan timeout, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | A TimeSpan to specify the timeout of the operation.
|
| CancellationToken | cancellationToken | An instance of CancellationToken to cancel the executing command delegate. |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
If the registered command handler is asynchronous (awaitable), then the execution is asynchronous otherwise the delegate is executed synchronously.
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | If the executing command delegate was cancelled. |
| ArgumentOutOfRangeException |
|
InvalidateCommand()
Raises the CanExecuteChanged event of this particular command only.
Declaration
void InvalidateCommand()