AsyncCommand
Ecng.ComponentModel
Async delegate command capable of taking argument.
继承自: NotifiableObject
实现: IRevalidatableCommand, ICommand, IDisposable
构造函数
AsyncCommand
public AsyncCommand(Func<T, CancellationToken, Task> execute, Func<T, bool> canExecute, bool allowMultipleExecution)
asyncCommand = AsyncCommand(execute, canExecute, allowMultipleExecution)
Creates a new async command.
- execute
- The async execution logic.
- canExecute
- The execution status logic.
- allowMultipleExecution
- Allow multiple concurrent executions.
AsyncCommand
public AsyncCommand(Func<T, Task> execute, Func<T, bool> canExecute, bool allowMultipleExecution)
asyncCommand = AsyncCommand(execute, canExecute, allowMultipleExecution)
Creates a new async command without cancellation support.
- execute
- The async execution logic.
- canExecute
- The execution status logic.
- allowMultipleExecution
- Allow multiple concurrent executions.
属性
CancelCommand
public IRevalidatableCommand CancelCommand { get; }
value = asyncCommand.CancelCommand
Gets the command to cancel the current execution.
IsCancellationRequested
public bool IsCancellationRequested { get; }
value = asyncCommand.IsCancellationRequested
Gets whether cancellation has been requested.
IsExecuting
public bool IsExecuting { get; private set; }
value = asyncCommand.IsExecuting
asyncCommand.IsExecuting = value
Gets whether the command is currently executing.
方法
Dispose
public void Dispose()
asyncCommand.Dispose()
Disposes the command and cancels any pending operation.
Dispose
protected virtual void Dispose(bool disposing)
asyncCommand.Dispose(disposing)
Disposes the command resources.
- disposing
- True if disposing managed resources.
ExecuteAsync
public Task ExecuteAsync(T parameter)
result = asyncCommand.ExecuteAsync(parameter)
Executes the command asynchronously.
- parameter
- The command parameter.
返回值: A task representing the async operation.
RaiseCanExecuteChanged
public void RaiseCanExecuteChanged()
asyncCommand.RaiseCanExecuteChanged()
Invoke CanExecuteChanged event.
事件
CanExecuteChanged
public event EventHandler CanExecuteChanged
asyncCommand.CanExecuteChanged += handler