System.Waf.Applications.AsyncDelegateCommand.Execute C# (CSharp) Method

Execute() public method

Defines the method to be called when the command is invoked.
public Execute ( object parameter ) : void
parameter object Data used by the command. If the command does not require data to be passed, this object can be set to null.
return void
        public async void Execute(object parameter)
        {
            if (!CanExecute(parameter))
            {
                return;
            }

            IsExecuting = true;
            try
            {
                await execute(parameter);
            }
            finally
            {
                IsExecuting = false;
            }
        }

Usage Example

Exemplo n.º 1
0
        public void CanExecuteDuringAsyncExecute2()
        {
            var tcs = new TaskCompletionSource<object>();
            var canExecute = false;
            var executeCalled = false;

            var command = new AsyncDelegateCommand(() =>
            {
                executeCalled = true;
                return tcs.Task;
            }, () => canExecute);

            Assert.IsFalse(command.CanExecute(null));
            command.Execute(null);
            Assert.IsFalse(executeCalled);

            canExecute = true;
            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);

            executeCalled = false;
            Assert.IsFalse(command.CanExecute(null));
            command.Execute(null);
            Assert.IsFalse(executeCalled);

            tcs.SetResult(null);
            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);
            Assert.IsTrue(executeCalled);
        }
All Usage Examples Of System.Waf.Applications.AsyncDelegateCommand::Execute