Table of Contents

Enum AsyncRelayCommandOptions

Namespace
CommunityToolkit.Mvvm.Input
Assembly
CommunityToolkit.Mvvm.dll

Options to customize the behavior of AsyncRelayCommand and AsyncRelayCommand<T> instances.

[Flags]
public enum AsyncRelayCommandOptions

Fields

AllowConcurrentExecutions = 1

Concurrent executions are allowed. This option makes it so that the same command can be invoked concurrently multiple times.

Note that additional considerations should be taken into account in this case:

  • If the command supports cancellation, previous invocations will automatically be canceled if a new one is started.
  • The ExecutionTask property will always represent the operation that was started last.
FlowExceptionsToTaskScheduler = 2

Exceptions are not thrown on the calling context, and are propagated to UnobservedTaskException instead.

This affects how calls to Execute(object?) behave. When this option is used, if an operation fails, that exception will not be rethrown on the calling context (as it is not awaited there). Instead, it will flow to UnobservedTaskException.

This option enables more advanced scenarios, where the ExecutionTask property can be used to inspect the state of an operation that was queued. That is, even if the operation failed or was canceled, the details of that can be retrieved at a later time by accessing this property.

None = 0

No option is specified. The AsyncRelayCommand and AsyncRelayCommand<T> types will use their default behavior:

  • Concurrent execution is disallowed: a command is disabled if there is a pending asynchronous execution running.
  • Exceptions are thrown on the calling context: calling Execute(object?) will await the returned Task for the operation, and propagate the exception on the calling context.

    This behavior is consistent with synchronous commands, where exceptions in Execute(object?) behave the same.