Interface IAsyncRelayCommand
- Namespace
- CommunityToolkit.Mvvm.Input
- Assembly
- CommunityToolkit.Mvvm.dll
An interface expanding IRelayCommand to support asynchronous operations.
public interface IAsyncRelayCommand : IRelayCommand, ICommand, INotifyPropertyChanged
- Inherited Members
- Extension Methods
Properties
CanBeCanceled
Gets a value indicating whether a running operation for this command can currently be canceled.
bool CanBeCanceled { get; }
Property Value
Remarks
The exact sequence of events that types implementing this interface should raise is as follows:
- The command is initially not running: IsRunning, CanBeCanceled and IsCancellationRequested are false.
- The command starts running: IsRunning and CanBeCanceled switch to true. IsCancellationRequested is set to false.
- If the operation is canceled: CanBeCanceled switches to false and IsCancellationRequested switches to true.
- The operation completes: IsRunning and CanBeCanceled switch to false. The state of IsCancellationRequested is undefined.
ExecutionTask
Gets the last scheduled Task, if available. This property notifies a change when the Task completes.
Task? ExecutionTask { get; }
Property Value
IsCancellationRequested
Gets a value indicating whether a cancelation request has been issued for the current operation.
bool IsCancellationRequested { get; }
Property Value
IsRunning
Gets a value indicating whether the command currently has a pending operation being executed.
bool IsRunning { get; }
Property Value
Methods
Cancel()
Communicates a request for cancelation.
void Cancel()
Remarks
If the underlying command is not running, or if it does not support cancelation, this method will perform no action. Note that even with a successful cancelation, the completion of the current operation might not be immediate.
ExecuteAsync(object?)
Provides a more specific version of Execute(object), also returning the Task representing the async operation being executed.
Task ExecuteAsync(object? parameter)
Parameters
parameter
objectThe input parameter.
Returns
Exceptions
- ArgumentException
Thrown if
parameter
is incompatible with the underlying command implementation.