Class AsyncRelayCommand
A reusable command that encapsulates the implementation of ICommand with support for async/await command delegates.
Enables instant creation of an ICommand without implementing the ICommand interface for each command.
The AsyncRelayCommand<TParam> accepts asynchronous command handlers and supports data bindng to properties like IsExecuting by implementing INotifyPropertyChanged.
Call and await the ExecuteAsync() method or one of its overloads to execute the command explicitly asynchronously.
ICommand
Inherited Members
Namespace: BionicCode.Utilities.Net
Assembly: BionicCode.Utilities.Net.dll
Syntax
public class AsyncRelayCommand : AsyncRelayCommandCommon, IAsyncRelayCommand, IAsyncRelayCommandCommon, ICommand, INotifyPropertyChanged
Remarks
AsyncRelayCommand implements ICommand. In case the AsyncRelayCommand<TParam> is executed explicitly, especially with an asynchronous command handler registered, it is highly recommended to invoke the awaitable ExecuteAsync() or its overloads instead.
Constructors
| Improve this Doc View SourceAsyncRelayCommand()
Declaration
protected AsyncRelayCommand()
AsyncRelayCommand(Action)
Creates a new parameterless synchronous command that can always execute (CanExecute() will always return true).
Declaration
public AsyncRelayCommand(Action executeNoParam)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | executeNoParam | The awaitable execution handler. |
AsyncRelayCommand(Action, Func<Boolean>)
Creates a new parameterless synchronous command.
Declaration
public AsyncRelayCommand(Action executeNoParam, Func<bool> canExecuteNoParam)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | executeNoParam | The execution handler. |
| Func<Boolean> | canExecuteNoParam | The execution status handler. |
AsyncRelayCommand(Action<CancellationToken>)
Creates a new parameterless synchronous command that can always execute (CanExecute() will always return true)
and supports cancellation.
Declaration
public AsyncRelayCommand(Action<CancellationToken> executeNoParam)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<CancellationToken> | executeNoParam | The awaitable execution handler. |
AsyncRelayCommand(Action<CancellationToken>, Func<Boolean>)
Declaration
public AsyncRelayCommand(Action<CancellationToken> executeAsync, Func<bool> canExecute)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<CancellationToken> | executeAsync | |
| Func<Boolean> | canExecute |
AsyncRelayCommand(Func<CancellationToken, Task>)
Creates a new parameterless asynchronous command that can always execute (CanExecute() will always return true)
and supports cancellation.
Declaration
public AsyncRelayCommand(Func<CancellationToken, Task> executeAsyncNoParam)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<CancellationToken, Task> | executeAsyncNoParam | The awaitable execution handler. |
AsyncRelayCommand(Func<CancellationToken, Task>, Func<Boolean>)
Creates a new parameterless asynchronous command that supports cancellation and does not take a command parameter.
Declaration
public AsyncRelayCommand(Func<CancellationToken, Task> executeAsync, Func<bool> canExecute)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<CancellationToken, Task> | executeAsync | The awaitable execution handler. |
| Func<Boolean> | canExecute | The can execute handler. |
AsyncRelayCommand(Func<Task>)
Creates a new parameterless asynchronous command that can always execute (CanExecute() will always return true).
Declaration
public AsyncRelayCommand(Func<Task> executeAsyncNoParam)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Task> | executeAsyncNoParam | The awaitable execution handler. |
AsyncRelayCommand(Func<Task>, Func<Boolean>)
Creates a parameterless new asynchronous command.
Declaration
public AsyncRelayCommand(Func<Task> executeAsyncNoParam, Func<bool> canExecuteNoParam)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Task> | executeAsyncNoParam | The awaitable execution handler. |
| Func<Boolean> | canExecuteNoParam | The execution status handler. |