Example #1
0
        private async Task DoExecuteAsync(object parameter)
        {
            await Task.Factory.StartNew(p =>
            {
                // Invoke the action.
                InvokeAction(p);

                ReportProgress(() =>
                {
                    // We are no longer executing.
                    IsExecuting = false;

                    // If we were cancelled, invoke the cancelled event - otherwise invoke executed.
                    if (IsCancellationRequested)
                    {
                        InvokeCancelled(new CommandEventArgs {
                            Parameter = p
                        });
                    }
                    else
                    {
                        InvokeExecuted(new CommandEventArgs {
                            Parameter = p
                        });
                    }

                    CancelCommand.NotifyCanExecuteChanged();
                });
            },
                                        parameter,
                                        _token);
        }
Example #2
0
        public override async void DoExecute(object paramObject)
        {
            if (IsExecuting)
            {
                return;
            }

            var args = new CancelCommandEventArgs
            {
                Parameter = paramObject,
                Cancel    = false
            };

            InvokeExecuting(args);

            if (args.Cancel)
            {
                return;
            }

            // We are executing.
            IsExecuting = true;
            CancelCommand.NotifyCanExecuteChanged();
            _cts   = new CancellationTokenSource();
            _token = _cts.Token;
            await DoExecuteAsync(paramObject);
        }