public DispatcherOperationEvent(DispatcherOperation op, TimeSpan timeout)
 {
     this._operation            = op;
     this._timeout              = timeout;
     this._event                = new AutoResetEvent(false);
     this._operation.Aborted   += new GHIElectronics.TinyCLR.UI.EventHandler(this.OnCompletedOrAborted);
     this._operation.Completed += new GHIElectronics.TinyCLR.UI.EventHandler(this.OnCompletedOrAborted);
     if (this._operation._status == DispatcherOperationStatus.Pending || this._operation._status == DispatcherOperationStatus.Executing)
     {
         return;
     }
     this._event.Set();
 }
Esempio n. 2
0
        internal bool Abort(DispatcherOperation operation)
        {
            bool flag = false;

            lock (this._instanceLock)
            {
                if (operation.Status == DispatcherOperationStatus.Pending)
                {
                    operation.Status = DispatcherOperationStatus.Aborted;
                    flag             = true;
                }
            }
            return(flag);
        }
Esempio n. 3
0
        // Returns whether or not the operation was removed.
        internal bool Abort(DispatcherOperation operation)
        {
            var notify = false;

            lock (this._instanceLock) {
                if (operation.Status == DispatcherOperationStatus.Pending)
                {
                    operation.Status = DispatcherOperationStatus.Aborted;
                    notify           = true;
                }
            }

            return(notify);
        }
Esempio n. 4
0
        public DispatcherOperation BeginInvoke(DispatcherOperationCallback method, object args)
        {
            if (method == null)
            {
                throw new ArgumentNullException();
            }
            DispatcherOperation dispatcherOperation = (DispatcherOperation)null;

            if (!this._hasShutdownFinished)
            {
                dispatcherOperation = new DispatcherOperation(this, method, args);
                this._queue.Enqueue((object)dispatcherOperation);
                this._event.Set();
            }
            return(dispatcherOperation);
        }
 public DispatcherOperationFrame(DispatcherOperation op, TimeSpan timeout)
     : base(false)
 {
     this._operation            = op;
     this._operation.Aborted   += new GHIElectronics.TinyCLR.UI.EventHandler(this.OnCompletedOrAborted);
     this._operation.Completed += new GHIElectronics.TinyCLR.UI.EventHandler(this.OnCompletedOrAborted);
     if (timeout.Ticks > 0L)
     {
         this._waitTimer = new Timer(new TimerCallback(this.OnTimeout), (object)null, timeout, new TimeSpan(-10000L));
     }
     if (this._operation._status == DispatcherOperationStatus.Pending)
     {
         return;
     }
     this.Exit();
 }
Esempio n. 6
0
        public object Invoke(TimeSpan timeout, DispatcherOperationCallback method, object args)
        {
            if (method == null)
            {
                throw new ArgumentNullException();
            }
            object obj = (object)null;
            DispatcherOperation dispatcherOperation = this.BeginInvoke(method, args);

            if (dispatcherOperation != null)
            {
                int num = (int)dispatcherOperation.Wait(timeout);
                if (dispatcherOperation.Status == DispatcherOperationStatus.Completed)
                {
                    obj = dispatcherOperation.Result;
                }
                else if (dispatcherOperation.Status != DispatcherOperationStatus.Aborted)
                {
                    dispatcherOperation.Abort();
                }
            }
            return(obj);
        }
Esempio n. 7
0
        /// <summary>
        ///     Executes the specified delegate asynchronously with the specified
        ///     arguments, on the thread that the Dispatcher was created on.
        /// </summary>
        /// <param name="method">
        ///     A delegate to a method that takes parameters of the same number
        ///     and type that are contained in the args parameter.
        /// </param>
        /// <param name="args">
        ///     An object to pass as the argument to the given method.
        ///     This can be null if no arguments are needed.
        /// </param>
        /// <returns>
        ///     A DispatcherOperation object that represents the result of the
        ///     BeginInvoke operation.  null if the operation could not be queued.
        /// </returns>
        public DispatcherOperation BeginInvoke(DispatcherOperationCallback method, object args)
        {
            if (method == null)
            {
                throw new ArgumentNullException();
            }

            DispatcherOperation operation = null;

            if (!this._hasShutdownFinished)
            {
                operation = new DispatcherOperation(this, method, args);

                // Add the operation to the work queue
                this._queue.Enqueue(operation);

                // this will only cause at most 1 extra dispatcher loop, so
                // always set the event.
                this._event.Set();
            }

            return(operation);
        }
Esempio n. 8
0
        //
        // instance implementation of PushFrame
        private void PushFrameImpl(DispatcherFrame frame)
        {
            var prevFrame = this._currentFrame;

            this._frameDepth++;
            try {
                this._currentFrame = frame;

                while (frame.Continue)
                {
                    DispatcherOperation op = null;
                    var aborted            = false;

                    //
                    // Dequeue the next operation if appropriate
                    if (this._queue.Count > 0)
                    {
                        op = (DispatcherOperation)this._queue.Dequeue();

                        //Must check aborted flag inside lock because
                        //user program could call op.Abort() between
                        //here and before the call to Invoke()
                        aborted = op.Status == DispatcherOperationStatus.Aborted;
                    }

                    if (op != null)
                    {
                        if (!aborted)
                        {
                            // Invoke the operation:
                            Debug.Assert(op._status == DispatcherOperationStatus.Pending);

                            // Mark this operation as executing.
                            op._status = DispatcherOperationStatus.Executing;

                            op._result = null;

                            try {
                                op._result = op._method(op._args);
                            }
                            catch (Exception e) {
                                if (this._finalExceptionHandler == null ||
                                    !this._finalExceptionHandler(op, e))
                                {
                                    throw;
                                }
                            }

                            // Mark this operation as completed.
                            op._status = DispatcherOperationStatus.Completed;

                            // Raise the Completed so anyone who is waiting will wake up.
                            op.OnCompleted();
                        }
                    }
                    else
                    {
                        this._event.WaitOne();
                    }
                }
            }
            finally {
                this._frameDepth--;

                this._currentFrame = prevFrame;

                // If this was the last frame to exit after a quit, we
                // can now dispose the dispatcher.
                if (this._frameDepth == 0)
                {
                    if (this._hasShutdownStarted)
                    {
                        ShutdownImpl();
                    }
                }
            }
        }