Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="DelegateCommandAsync{T}"/>.
        /// </summary>
        /// <param name="executeMethod">Delegate to execute when Execute is called on the command. This can be null to just hook up a CanExecute delegate.</param>
        /// <param name="canExecuteMethod">Delegate to execute when CanExecute is called on the command. This can be null.</param>
        /// <exception cref="ArgumentNullException">When both <paramref name="executeMethod"/> and <paramref name="canExecuteMethod"/> ar <see langword="null" />.</exception>
        public DelegateCommandAsync(Func <CancellationToken, Task> executeMethod, Func <bool> canExecuteMethod)
            : base()
        {
            if (executeMethod == null || canExecuteMethod == null)
            {
                throw new ArgumentNullException(nameof(executeMethod), "DelegateCommand Delegates Cannot Be Null");
            }

            cancelCommand         = new CancelTaskCommand();
            this.executeMethod    = executeMethod;
            this.canExecuteMethod = canExecuteMethod;
        }
 public ObservableTask(Func <CancellationToken, Task> executeMethod)
 {
     CancelCommand  = new CancelTaskCommand();
     Task           = executeMethod(CancelCommand.Token);
     TaskCompletion = WatchTaskAsync(Task);
 }