Class AsyncDelegateCommand
The AsyncDelegateCommand allows use the System.Windows.Input.ICommand interface with asynchronous functionality. While the underlying asynchronous functionality is running System.Windows.Input.ICommand.CanExecute(System.Object) always returns false and System.Windows.Input.ICommand.CanExecuteChanged is automatically called when execution starts and ends.
potential exceptions occurring during execution are automatically dispatched into the UI thread.
Namespace: Sartorius.SAF.Presentation.Commands
Assembly: Sartorius.SAF.Presentation.dll
Syntax
public sealed class AsyncDelegateCommand : AsyncDelegateCommandBase, IAsyncDelegateCommand, ICommand
  Examples
The following example shows how to use the AsyncDelegateCommand.
    [Export]
public class AddViewModel
{
    private readonly AsyncDelegateCommand addCommand;
    private readonly IItemService service;
    [ImportingConstructor]
    public AddViewModel(IItemService service)
    {
        this.service = service;
        this.addCommand = new AsyncDelegateCommand(OnAdd);
    }
    public ICommand AddCommand => this.addCommand;
    private async Task OnAdd()
    {
        using (new BusyIndicator())
        {
            await this.service.AddAsync(new Item())
                      .ConfigureAwait(true);
        } // disposal of BusyIndicator is done in UI thread
    }
}
  Constructors
View SourceAsyncDelegateCommand(Func<Task>)
Creates a new instance of the AsyncDelegateCommand class with the specified async execution function.
Declaration
public AsyncDelegateCommand(Func<Task> executeFunc)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Func<System.Threading.Tasks.Task> | executeFunc | The asynchronous function that this command should execute.  | 
      
AsyncDelegateCommand(Func<Task>, Func<Boolean>)
Creates a new instance of the AsyncDelegateCommand class with the specified async execution function and can execute function.
Declaration
public AsyncDelegateCommand(Func<Task> executeFunc, Func<bool> canExecute)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Func<System.Threading.Tasks.Task> | executeFunc | The asynchronous function that this command should execute.  | 
      
| System.Func<System.Boolean> | canExecute | The function that verifies whether the command can execute in its current state.  | 
      
Methods
View SourceCanExecute()
Defines the method that determines whether the command can execute in its current state.
Declaration
public bool CanExecute()
  Returns
| Type | Description | 
|---|---|
| System.Boolean | 
  | 
      
ExecuteAsync()
Defines the method to be called when the command is invoked.
Declaration
public async Task ExecuteAsync()
  Returns
| Type | Description | 
|---|---|
| System.Threading.Tasks.Task | The task object representing the asynchronous operation.  | 
      
Explicit Interface Implementations
View SourceICommand.CanExecute(Object)
Declaration
bool ICommand.CanExecute(object parameter)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Object | parameter | 
Returns
| Type | Description | 
|---|---|
| System.Boolean | 
ICommand.Execute(Object)
Declaration
void ICommand.Execute(object parameter)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Object | parameter |