Table of Contents

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

bool

Remarks

The exact sequence of events that types implementing this interface should raise is as follows:

This only applies if the underlying logic for the command actually supports cancelation. If that is not the case, then CanBeCanceled and IsCancellationRequested will always remain false regardless of the current state of the command.

ExecutionTask

Gets the last scheduled Task, if available. This property notifies a change when the Task completes.

Task? ExecutionTask { get; }

Property Value

Task

IsCancellationRequested

Gets a value indicating whether a cancelation request has been issued for the current operation.

bool IsCancellationRequested { get; }

Property Value

bool

IsRunning

Gets a value indicating whether the command currently has a pending operation being executed.

bool IsRunning { get; }

Property Value

bool

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 object

The input parameter.

Returns

Task

The Task representing the async operation being executed.

Exceptions

ArgumentException

Thrown if parameter is incompatible with the underlying command implementation.