Esempio n. 1
0
        /// <summary>
        /// Defines the method to be called when the command is invoked.
        /// </summary>
        /// <param name="value">Data used by the command.  If the command does not require data to be passed, this object can be set to null.</param>
        public void Execute(object value)
        {
            using (var token = access.AccquireUpgradeableReaderLock())
            {
                if (false == CanExecute(value))
                {
                    return;
                }

                executeChanged.Invoke(this, EventArgs.Empty);

                using (token.Upgrade())
                {
                    if (IsExecuting)
                    {
                        return;
                    }

                    try
                    {
                        IsExecuting = true;
                        cts         = new CancellationTokenSource();

                        Task.Factory.StartNew(DoExecute, value, cts.Token).RunAndForget();
                    }
                    catch (Exception)
                    {
                        IsExecuting = false;
                        complete.Invoke(this, new CommandCompleteEventArgs(CompleteStatus.Failed));
                    }
                }
            }
        }