// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.ComponentModel; using System.Threading.Tasks; namespace CommunityToolkit.Mvvm.Input; /// /// An interface expanding to support asynchronous operations. /// public interface IAsyncRelayCommand : IRelayCommand, INotifyPropertyChanged { /// /// Gets the last scheduled , if available. /// This property notifies a change when the completes. /// Task? ExecutionTask { get; } /// /// Gets a value indicating whether a running operation for this command can currently be canceled. /// /// /// The exact sequence of events that types implementing this interface should raise is as follows: /// /// /// The command is initially not running: , /// and are . /// /// /// The command starts running: and switch to /// . is set to . /// /// /// If the operation is canceled: switches to /// and switches to . /// /// /// The operation completes: and switch /// to . The state of is undefined. /// /// /// This only applies if the underlying logic for the command actually supports cancelation. If that is /// not the case, then and will always remain /// regardless of the current state of the command. /// bool CanBeCanceled { get; } /// /// Gets a value indicating whether a cancelation request has been issued for the current operation. /// bool IsCancellationRequested { get; } /// /// Gets a value indicating whether the command currently has a pending operation being executed. /// bool IsRunning { get; } /// /// Provides a more specific version of , /// also returning the representing the async operation being executed. /// /// The input parameter. /// The representing the async operation being executed. /// Thrown if is incompatible with the underlying command implementation. Task ExecuteAsync(object? parameter); /// /// Communicates a request for cancelation. /// /// /// 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. /// void Cancel(); }