예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RelayCommand&lt;PingUIOperations&gt;"/> class.
 /// </summary>
 /// <param name="operationId">The operation id.</param>
 /// <param name="canExecute">The can execute method. use <c>null</c> to skip the check.</param>
 /// <param name="beginExecute">The begin execute method. Method that should be called when execution
 /// completed should be specified in the <see cref="IAsyncCallContext.EndCall"/> inside the <c>beginExecute</c>.</param>
 public RelayCommand(UIOperations operationId, BeginAsyncOperationAction beginExecute, Predicate <object> canExecute)
 {
     this._operationId = operationId;
     this._canExecute  = canExecute;
     this._execute     = (prm) => {
         this.IsExecuting = null !=
                            beginExecute(this._asyncContext = new WinAsyncCallContext(this.OperationId, prm), EndAsyncOperation);
     };
 }
예제 #2
0
        /// <summary>
        /// Aborts the execution.
        /// </summary>
        public virtual bool Abort()
        {
            WinAsyncCallContext asyncCtx = this._asyncContext;

            if (this.IsExecuting && (asyncCtx != null) && this._asyncContext.AbortCall != null)
            {
                return(asyncCtx.AbortCall(asyncCtx));
            }
            return(false);
        }
예제 #3
0
        void EndAsyncOperation(IAsyncResult asyncResult)
        {
            this._asyncContext = null; // Clear the cached reference
            WinAsyncCallContext asyncCallContext = ((WinAsyncCallContext)(asyncResult.AsyncState));

            asyncCallContext.RestoreThreadContext();
            if (asyncCallContext.Dispatcher.CheckAccess())
            {
                this.IsExecuting = false;
                asyncCallContext.EndCall(asyncResult);
            }
            else
            {
                asyncCallContext.Dispatcher.BeginInvoke(new Action(() => {
                    this.IsExecuting = false;
                    asyncCallContext.EndCall(asyncResult);
                }));
            }
        }