Class AsyncRelayCommand
A command that mirrors the functionality of RelayCommand, with the addition of accepting a Func<TResult> returning a Task as the execute action, and providing an executionTask property that notifies changes when ExecuteAsync(Object) is invoked and when the returned Task completes.
Inherited Members
Namespace: Unity.AppUI.MVVM
Syntax
public class AsyncRelayCommand : IAsyncRelayCommand, IRelayCommand, ICommand, INotifyPropertyChanged
Constructors
AsyncRelayCommand(Func<CancellationToken, Task>)
Initializes a new instance of the AsyncRelayCommand class.
Declaration
public AsyncRelayCommand(Func<CancellationToken, Task> cancellableExecute)
Parameters
Type | Name | Description |
---|---|---|
Func<CancellationToken, Task> | cancellableExecute | The Func<TResult> to invoke when ExecuteAsync(Object) is called. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the execute argument is null. |
AsyncRelayCommand(Func<CancellationToken, Task>, Func<Boolean>)
Initializes a new instance of the AsyncRelayCommand class.
Declaration
public AsyncRelayCommand(Func<CancellationToken, Task> cancellableExecute, Func<bool> canExecute)
Parameters
Type | Name | Description |
---|---|---|
Func<CancellationToken, Task> | cancellableExecute | The Func<TResult> to invoke when ExecuteAsync(Object) is called. |
Func<Boolean> | canExecute | The Func<TResult> to invoke when CanExecute() is called. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the execute argument is null. |
AsyncRelayCommand(Func<CancellationToken, Task>, Func<Boolean>, AsyncRelayCommandOptions)
Initializes a new instance of the AsyncRelayCommand class.
Declaration
public AsyncRelayCommand(Func<CancellationToken, Task> cancellableExecute, Func<bool> canExecute, AsyncRelayCommandOptions options)
Parameters
Type | Name | Description |
---|---|---|
Func<CancellationToken, Task> | cancellableExecute | The Func<TResult> to invoke when ExecuteAsync(Object) is called. |
Func<Boolean> | canExecute | The Func<TResult> to invoke when CanExecute() is called. |
AsyncRelayCommandOptions | options | The AsyncRelayCommandOptions to use. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the execute argument is null. |
AsyncRelayCommand(Func<CancellationToken, Task>, AsyncRelayCommandOptions)
Initializes a new instance of the AsyncRelayCommand class.
Declaration
public AsyncRelayCommand(Func<CancellationToken, Task> cancellableExecute, AsyncRelayCommandOptions options)
Parameters
Type | Name | Description |
---|---|---|
Func<CancellationToken, Task> | cancellableExecute | The Func<TResult> to invoke when ExecuteAsync(Object) is called. |
AsyncRelayCommandOptions | options | The AsyncRelayCommandOptions to use. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the execute argument is null. |
AsyncRelayCommand(Func<Task>)
Initializes a new instance of the AsyncRelayCommand class.
Declaration
public AsyncRelayCommand(Func<Task> execute)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | execute | The Func<TResult> to invoke when ExecuteAsync(Object) is called. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the execute argument is null. |
AsyncRelayCommand(Func<Task>, Func<Boolean>)
Initializes a new instance of the AsyncRelayCommand class.
Declaration
public AsyncRelayCommand(Func<Task> execute, Func<bool> canExecute)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | execute | The Func<TResult> to invoke when ExecuteAsync(Object) is called. |
Func<Boolean> | canExecute | The Func<TResult> to invoke when CanExecute() is called. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the execute argument is null. |
AsyncRelayCommand(Func<Task>, Func<Boolean>, AsyncRelayCommandOptions)
Initializes a new instance of the AsyncRelayCommand class.
Declaration
public AsyncRelayCommand(Func<Task> execute, Func<bool> canExecute, AsyncRelayCommandOptions options)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | execute | The Func<TResult> to invoke when ExecuteAsync(Object) is called. |
Func<Boolean> | canExecute | The Func<TResult> to invoke when CanExecute() is called. |
AsyncRelayCommandOptions | options | The AsyncRelayCommandOptions to use. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the execute argument is null. |
AsyncRelayCommand(Func<Task>, AsyncRelayCommandOptions)
Initializes a new instance of the AsyncRelayCommand class.
Declaration
public AsyncRelayCommand(Func<Task> execute, AsyncRelayCommandOptions options)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | execute | The Func<TResult> to invoke when ExecuteAsync(Object) is called. |
AsyncRelayCommandOptions | options | The AsyncRelayCommandOptions to use. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If the execute argument is null. |
Fields
CanBeCanceledChangedEventArgs
The arguments for the PropertyChanged event raised by the canBeCancelled property.
Declaration
public static readonly PropertyChangedEventArgs CanBeCanceledChangedEventArgs
Field Value
Type | Description |
---|---|
PropertyChangedEventArgs |
ExecutionTaskChangedEventArgs
The arguments for the PropertyChanged event raised by the executionTask property.
Declaration
public static readonly PropertyChangedEventArgs ExecutionTaskChangedEventArgs
Field Value
Type | Description |
---|---|
PropertyChangedEventArgs |
IsCancellationRequestedChangedEventArgs
The arguments for the PropertyChanged event raised by the isCancellationRequested property.
Declaration
public static readonly PropertyChangedEventArgs IsCancellationRequestedChangedEventArgs
Field Value
Type | Description |
---|---|
PropertyChangedEventArgs |
IsRunningChangedEventArgs
The arguments for the PropertyChanged event raised by the isRunning property.
Declaration
public static readonly PropertyChangedEventArgs IsRunningChangedEventArgs
Field Value
Type | Description |
---|---|
PropertyChangedEventArgs |
Properties
canBeCancelled
Gets the CancellationTokenSource that can be used to cancel the asynchronous operation.
Declaration
public bool canBeCancelled { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
executionTask
Gets the Task that represents the asynchronous operation.
Declaration
public Task executionTask { get; set; }
Property Value
Type | Description |
---|---|
Task |
Implements
isCancellationRequested
Gets the CancellationTokenSource that can be used to cancel the asynchronous operation.
Declaration
public bool isCancellationRequested { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
isRunning
Gets the CancellationTokenSource that can be used to cancel the asynchronous operation.
Declaration
public bool isRunning { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
Methods
Cancel()
Cancels the AsyncRelayCommand on the current command target.
Declaration
public void Cancel()
Implements
CanExecute()
Determines whether this AsyncRelayCommand can execute in its current state.
Declaration
public bool CanExecute()
Returns
Type | Description |
---|---|
Boolean | true if this AsyncRelayCommand can execute; otherwise, false. |
CanExecute(Object)
Determines whether this AsyncRelayCommand can execute in its current state.
Declaration
public bool CanExecute(object parameter)
Parameters
Type | Name | Description |
---|---|---|
Object | parameter | The parameter to use when determining whether this AsyncRelayCommand can execute. |
Returns
Type | Description |
---|---|
Boolean | true if this AsyncRelayCommand can execute; otherwise, false. |
Implements
Execute()
Executes the AsyncRelayCommand on the current command target.
Declaration
public void Execute()
Execute(Object)
Executes the AsyncRelayCommand on the current command target.
Declaration
public void Execute(object parameter)
Parameters
Type | Name | Description |
---|---|---|
Object | parameter | The parameter to use when executing the AsyncRelayCommand. |
Implements
ExecuteAsync(Object)
Executes the AsyncRelayCommand on the current command target.
Declaration
public Task ExecuteAsync(object parameter)
Parameters
Type | Name | Description |
---|---|---|
Object | parameter | The parameter to use when executing the AsyncRelayCommand. |
Returns
Type | Description |
---|---|
Task | The Task that represents the asynchronous operation. |
Implements
NotifyCanExecuteChanged()
Raises the CanExecuteChanged event.
Declaration
public void NotifyCanExecuteChanged()
Implements
Events
CanExecuteChanged
Event that is raised when changes occur that affect whether or not the AsyncRelayCommand should execute.
Declaration
public event EventHandler CanExecuteChanged
Event Type
Type | Description |
---|---|
EventHandler |
Implements
PropertyChanged
Event that is raised when the executionTask property changes.
Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
Type | Description |
---|---|
PropertyChangedEventHandler |