Search Results for

    Show / Hide Table of Contents

    Class AsyncRelayCommandCommon

    A reusable command that encapsulates the implementation of ICommand with support for async/await command delegates.
    Enables instant creation of an ICommand without implementing the ICommand interface for each command. The AsyncRelayCommandCommon<TParam> accepts asynchronous command handlers and supports data bindng to properties like IsExecuting by implementing INotifyPropertyChanged.
    Call and await the ExecuteAsync() method or one of its overloads to execute the command explicitly asynchronously. ICommand

    Inheritance
    Object
    AsyncRelayCommandCommon
    AsyncRelayCommand
    AsyncRelayCommandCommon<TParam>
    Implements
    IAsyncRelayCommandCommon
    ICommand
    INotifyPropertyChanged
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: BionicCode.Utilities.Net
    Assembly: BionicCode.Utilities.Net.Common.dll
    Syntax
    public abstract class AsyncRelayCommandCommon : IAsyncRelayCommandCommon, ICommand, INotifyPropertyChanged
    Remarks

    AsyncRelayCommandCommon implements ICommand. In case the AsyncRelayCommandCommon<TParam> is executed explicitly, especially with an asynchronous command handler registered, it is highly recommended to invoke the awaitable ExecuteAsync() or its overloads instead.

    Constructors

    | Improve this Doc View Source

    AsyncRelayCommandCommon()

    Constructor

    Declaration
    protected AsyncRelayCommandCommon()
    | Improve this Doc View Source

    AsyncRelayCommandCommon(Action)

    Creates a new parameterless synchronous command that can always execute (CanExecute() will always return true).

    Declaration
    protected AsyncRelayCommandCommon(Action executeNoParam)
    Parameters
    Type Name Description
    Action executeNoParam

    The awaitable execution handler.

    | Improve this Doc View Source

    AsyncRelayCommandCommon(Action, Func<Boolean>)

    Creates a new parameterless synchronous command.

    Declaration
    protected AsyncRelayCommandCommon(Action executeNoParam, Func<bool> canExecuteNoParam)
    Parameters
    Type Name Description
    Action executeNoParam

    The execution handler.

    Func<Boolean> canExecuteNoParam

    The execution status handler.

    | Improve this Doc View Source

    AsyncRelayCommandCommon(Action<CancellationToken>)

    Creates a new parameterless synchronous command that can always execute (CanExecute() will always return true)
    and supports cancellation.

    Declaration
    protected AsyncRelayCommandCommon(Action<CancellationToken> executeNoParam)
    Parameters
    Type Name Description
    Action<CancellationToken> executeNoParam

    The awaitable execution handler.

    | Improve this Doc View Source

    AsyncRelayCommandCommon(Action<CancellationToken>, Func<Boolean>)

    Creates a new parameterless synchronous command that supports cancellation.

    Declaration
    protected AsyncRelayCommandCommon(Action<CancellationToken> executeCancellable, Func<bool> canExecute)
    Parameters
    Type Name Description
    Action<CancellationToken> executeCancellable

    The awaitable execution handler.

    Func<Boolean> canExecute

    The can execute handler.

    | Improve this Doc View Source

    AsyncRelayCommandCommon(Func<CancellationToken, Task>)

    Creates a new parameterless asynchronous command that can always execute (CanExecute() will always return true)
    and supports cancellation.

    Declaration
    protected AsyncRelayCommandCommon(Func<CancellationToken, Task> executeAsyncNoParam)
    Parameters
    Type Name Description
    Func<CancellationToken, Task> executeAsyncNoParam

    The awaitable execution handler.

    | Improve this Doc View Source

    AsyncRelayCommandCommon(Func<CancellationToken, Task>, Func<Boolean>)

    Creates a new parameterless asynchronous command that supports cancellation and does not take a command parameter.

    Declaration
    protected AsyncRelayCommandCommon(Func<CancellationToken, Task> executeAsync, Func<bool> canExecute)
    Parameters
    Type Name Description
    Func<CancellationToken, Task> executeAsync

    The awaitable execution handler.

    Func<Boolean> canExecute

    The can execute handler.

    | Improve this Doc View Source

    AsyncRelayCommandCommon(Func<Task>)

    Creates a new parameterless asynchronous command that can always execute (CanExecute() will always return true).

    Declaration
    protected AsyncRelayCommandCommon(Func<Task> executeAsyncNoParam)
    Parameters
    Type Name Description
    Func<Task> executeAsyncNoParam

    The awaitable execution handler.

    | Improve this Doc View Source

    AsyncRelayCommandCommon(Func<Task>, Func<Boolean>)

    Creates a parameterless new asynchronous command.

    Declaration
    protected AsyncRelayCommandCommon(Func<Task> executeAsyncNoParam, Func<bool> canExecuteNoParam)
    Parameters
    Type Name Description
    Func<Task> executeAsyncNoParam

    The awaitable execution handler.

    Func<Boolean> canExecuteNoParam

    The execution status handler.

    Fields

    | Improve this Doc View Source

    MaxThreads

    The number of concurrent threads than can execute a command delegate.

    Declaration
    protected const int MaxThreads = 1
    Field Value
    Type Description
    Int32

    Properties

    | Improve this Doc View Source

    CanBeCanceled

    Returns whether the command can be cancelled.

    Declaration
    public bool CanBeCanceled { get; }
    Property Value
    Type Description
    Boolean

    true if cancellation is allowed. Otherwise false.

    | Improve this Doc View Source

    CanExecuteNoParamDelegate

    The registered parameterless CanExecute delegate.

    Declaration
    protected Func<bool> CanExecuteNoParamDelegate { get; }
    Property Value
    Type Description
    Func<Boolean>

    true if the command can execute, otherwise false.

    | Improve this Doc View Source

    CurrentCancellationToken

    The currently used CancellationToken.

    Declaration
    public CancellationToken CurrentCancellationToken { get; }
    Property Value
    Type Description
    CancellationToken

    A CancellationToken instance currently in use during the command execution.

    Remarks

    This property can be used to query the state of the cancellation or to register a cancellation callback by calling Register(Action).
    The instance will change for each command execution.

    | Improve this Doc View Source

    ExecuteAsyncNoParamDelegate

    The registered parameterless async execute delegate.

    Declaration
    protected Func<Task> ExecuteAsyncNoParamDelegate { get; }
    Property Value
    Type Description
    Func<Task>

    A delegate that takes no command parameter and returns a Task.

    | Improve this Doc View Source

    ExecuteCancellableAsyncNoParamDelegate

    The registered parameterless async execute delegate that supports cancellation.

    Declaration
    protected Func<CancellationToken, Task> ExecuteCancellableAsyncNoParamDelegate { get; }
    Property Value
    Type Description
    Func<CancellationToken, Task>

    A delegate that supports cancellation, but takes no command parameter and returns a Task.

    | Improve this Doc View Source

    ExecuteCancellableNoParamDelegate

    The registered parameterless synchronous execute delegate that supports cancellation.

    Declaration
    protected Action<CancellationToken> ExecuteCancellableNoParamDelegate { get; }
    Property Value
    Type Description
    Action<CancellationToken>

    A delegate that suppoprts cancellation, but takes no command parameter and returns void.

    | Improve this Doc View Source

    ExecuteNoParamDelegate

    The registered parameterless synchronous execute delegate.

    Declaration
    protected Action ExecuteNoParamDelegate { get; }
    Property Value
    Type Description
    Action

    A delegate that takes no parameter and returns void.

    | Improve this Doc View Source

    HasPending

    Return whether the command has pending executions.

    Declaration
    public bool HasPending { get; }
    Property Value
    Type Description
    Boolean
    Remarks

    Only one command is executed at time. Sucessive command invocations are enqueued and run after the currently executing delegate has completed
    or was cancelled.

    | Improve this Doc View Source

    IsCancelled

    Returns whether the command's executing operation was cancelled.

    Declaration
    public bool IsCancelled { get; }
    Property Value
    Type Description
    Boolean

    true if the last command execution was cancelled. Otherwise false.

    | Improve this Doc View Source

    IsExecuting

    A flag to signal if the asynchronous operation has completed.

    Declaration
    public bool IsExecuting { get; }
    Property Value
    Type Description
    Boolean
    | Improve this Doc View Source

    IsPendingCancelled

    Returns whether the command's pending operations were cancelled.

    Declaration
    public bool IsPendingCancelled { get; }
    Property Value
    Type Description
    Boolean

    true if the last command execution was cancelled. Otherwise false.

    | Improve this Doc View Source

    PendingCount

    Returns the number of pending command delegate executions.

    Declaration
    public int PendingCount { get; }
    Property Value
    Type Description
    Int32

    Methods

    | Improve this Doc View Source

    CancelAll()

    Cancels all pending and executing commands.

    Declaration
    public void CancelAll()
    Remarks

    See Cancel() for the exception behavior of this overload.

    | Improve this Doc View Source

    CancelAll(Boolean)

    Cancels all pending and executing commands.

    Declaration
    public void CancelAll(bool throwOnFirstException)
    Parameters
    Type Name Description
    Boolean throwOnFirstException

    See Cancel(Boolean) for the effects of the parameter.

    Remarks

    See Cancel(Boolean) for the exception behavior of this overload.

    | Improve this Doc View Source

    CancelExecuting()

    Cancels the currently executing command.

    Declaration
    public void CancelExecuting()
    Remarks

    See Cancel() for the exception behavior of this overload.

    | Improve this Doc View Source

    CancelExecuting(Boolean)

    Cancels the currently executing command.

    Declaration
    public void CancelExecuting(bool throwOnFirstException)
    Parameters
    Type Name Description
    Boolean throwOnFirstException

    See Cancel(Boolean) for the effects of the parameter.

    Remarks

    See Cancel(Boolean) for the exception behavior of this overload.

    | Improve this Doc View Source

    CancelPending()

    Cancels all pending command executions.

    Declaration
    public void CancelPending()
    Remarks

    See Cancel() for the exception behavior of this overload.

    | Improve this Doc View Source

    CancelPending(Boolean)

    Cancels all pending command executions.

    Declaration
    public void CancelPending(bool throwOnFirstException)
    Parameters
    Type Name Description
    Boolean throwOnFirstException

    See Cancel(Boolean) for the effects of the parameter.

    Remarks

    See Cancel(Boolean) for the exception behavior of this overload.

    | Improve this Doc View Source

    CanExecute()

    Determines whether this AsyncRelayCommandCommon can execute.

    Declaration
    public bool CanExecute()
    Returns
    Type Description
    Boolean

    true if this command can be executed, otherwise false.

    | Improve this Doc View Source

    ExecuteAsync()

    Executes the AsyncRelayCommand on the current command target asynchronously.

    Declaration
    public async Task ExecuteAsync()
    Returns
    Type Description
    Task
    Remarks

    If the registered command handler is asynchronous (awaitable), then the execution is asynchronous otherwise the delegate is executed synchronously.

    | Improve this Doc View Source

    ExecuteAsync(CancellationToken)

    Executes the AsyncRelayCommand on the current command target asynchronously.

    Declaration
    public async Task ExecuteAsync(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    An instance of CancellationToken to cancel the executing command delegate.

    Returns
    Type Description
    Task
    Remarks

    If the registered command handler is asynchronous (awaitable), then the execution is asynchronous otherwise the delegate is executed synchronously.

    Only one command is executed at time. Sucessive command invocations are enqueued and run after the currently executing delegate has completed
    or was cancelled. Query HasPending to know if the command has pending delegate executions and PendingCount to knwo the number of pending delegate executions.

    Exceptions
    Type Condition
    OperationCanceledException

    If executing command delegate was cancelled.

    | Improve this Doc View Source

    ExecuteAsync(TimeSpan)

    Executes the AsyncRelayCommand on the current command target asynchronously.

    Declaration
    public async Task ExecuteAsync(TimeSpan timeout)
    Parameters
    Type Name Description
    TimeSpan timeout

    A TimeSpan to specify the timeout of the operation.
    A value of InfiniteTimeSpan (or a TimeSpan that represents -1) will specifiy an infinite time out.
    A value of Zero will cancel the operation immediately.

    Returns
    Type Description
    Task
    Remarks

    If the registered command handler is asynchronous (awaitable), then the execution is asynchronous otherwise the delegate is executed synchronously.

    Only one command is executed at time. Sucessive command invocations are enqueued and run after the currently executing delegate has completed
    or was cancelled. Query HasPending to know if the command has pending delegate executions and PendingCount to knwo the number of pending delegate executions.

    Exceptions
    Type Condition
    OperationCanceledException

    If the executing command delegate was cancelled.

    | Improve this Doc View Source

    ExecuteAsync(TimeSpan, CancellationToken)

    Executes the AsyncRelayCommand on the current command target asynchronously.

    Declaration
    public virtual async Task ExecuteAsync(TimeSpan timeout, CancellationToken cancellationToken)
    Parameters
    Type Name Description
    TimeSpan timeout

    A TimeSpan to specify the timeout of the operation.
    A value of InfiniteTimeSpan (or a TimeSpan that represents -1) will specifiy an infinite time out.
    A value of Zero will cancel the operation immediately.

    CancellationToken cancellationToken

    An instance of CancellationToken to cancel the executing command delegate.

    Returns
    Type Description
    Task
    Remarks

    If the registered command handler is asynchronous (awaitable), then the execution is asynchronous otherwise the delegate is executed synchronously.

    Exceptions
    Type Condition
    OperationCanceledException

    If the executing command delegate was cancelled.

    ArgumentOutOfRangeException

    timeout>>.TotalMilliseconds is less than -1 or greater than MaxValue (or MaxValue - 1 on some versions of .NET). Note that this upper bound is more restrictive than MaxValue.

    | Improve this Doc View Source

    InvalidateCommand()

    Raises the CanExecuteChanged event of this particular command only.

    Declaration
    public void InvalidateCommand()
    | Improve this Doc View Source

    OnCanExecuteChanged()

    Raises the CanExecuteChanged event.

    Declaration
    protected virtual void OnCanExecuteChanged()
    | Improve this Doc View Source

    OnPropertyChanged(String)

    Raises the PropertyChanged event.

    Declaration
    protected virtual void OnPropertyChanged(string propertyName = "")
    Parameters
    Type Name Description
    String propertyName
    | Improve this Doc View Source

    TryExecuteNoParamCommand()

    Declaration
    protected async Task<bool> TryExecuteNoParamCommand()
    Returns
    Type Description
    Task<Boolean>

    Events

    | Improve this Doc View Source

    CanExecuteChanged

    Declaration
    public event EventHandler CanExecuteChanged
    Event Type
    Type Description
    EventHandler
    | Improve this Doc View Source

    PropertyChanged

    Declaration
    public event PropertyChangedEventHandler PropertyChanged
    Event Type
    Type Description
    PropertyChangedEventHandler

    Explicit Interface Implementations

    | Improve this Doc View Source

    ICommand.CanExecute(Object)

    Declaration
    bool ICommand.CanExecute(object parameter)
    Parameters
    Type Name Description
    Object parameter
    Returns
    Type Description
    Boolean
    | Improve this Doc View Source

    ICommand.Execute(Object)

    Declaration
    async void ICommand.Execute(object parameter)
    Parameters
    Type Name Description
    Object parameter

    Implements

    IAsyncRelayCommandCommon
    ICommand
    INotifyPropertyChanged

    Extension Methods

    HelperExtensionsCommon.ToDictionary(Object)
    HelperExtensionsCommon.ToFlatDictionary(Object)
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX