docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface IAsyncRelayCommand

    An interface expanding IRelayCommand to support asynchronous operations.

    Inherited Members
    IRelayCommand.NotifyCanExecuteChanged()
    ICommand.CanExecute(object)
    ICommand.Execute(object)
    ICommand.CanExecuteChanged
    INotifyPropertyChanged.PropertyChanged
    Namespace: Unity.AppUI.MVVM
    Assembly: Unity.AppUI.MVVM.dll
    Syntax
    public interface IAsyncRelayCommand : IRelayCommand, ICommand, INotifyPropertyChanged

    Properties

    canBeCancelled

    Gets a value indicating whether a running operation for this command can currently be canceled.

    Declaration
    bool canBeCancelled { get; }
    Property Value
    Type Description
    bool
    Remarks

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

    • The command is initially not running: isRunning, canBeCancelled and isCancellationRequested are false.
    • The command starts running: isRunning and canBeCancelled switch to true. isCancellationRequested is set to false.
    • If the operation is canceled: canBeCancelled switches to false and isCancellationRequested switches to true.
    • The operation completes: isRunning and canBeCancelled switch to false. The state of isCancellationRequested is undefined.
    This only applies if the underlying logic for the command actually supports cancellation. If that is not the case, then canBeCancelled 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.

    Declaration
    Task? executionTask { get; }
    Property Value
    Type Description
    Task

    isCancellationRequested

    Gets a value indicating whether a running operation for this command has been cancelled.

    Declaration
    bool isCancellationRequested { get; }
    Property Value
    Type Description
    bool

    isRunning

    Gets a value indicating whether an operation for this command is currently running.

    Declaration
    bool isRunning { get; }
    Property Value
    Type Description
    bool

    Methods

    Cancel()

    Attempts to cancel the currently running operation for this command.

    Declaration
    void Cancel()

    ExecuteAsync(object?)

    Executes the command asynchronously.

    Declaration
    Task ExecuteAsync(object? parameter)
    Parameters
    Type Name Description
    object parameter

    The input parameter.

    Returns
    Type Description
    Task

    A Task representing the asynchronous operation.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)