Example #1
0
 private void OnLogUpdated()
 {
     if (logTask == null || logTask.Status == DispatcherOperationStatus.Completed || logTask.Status == DispatcherOperationStatus.Aborted)
     {
         logTask = Dispatcher.InvokeAsync(() =>
         {
             terminal.Text = log.text;
             terminalScroll.ScrollToBottom();
         });
     }
 }
        public void BeginUpdateLayout()
        {
            if (updateLayoutOperation == null || updateLayoutOperation.Status == DispatcherOperationStatus.Completed)
            {
#if MIGRATION
                updateLayoutOperation = Dispatcher.INTERNAL_GetCurrentDispatcher().InvokeAsync(UpdateLayout, DispatcherPriority.Render);
#else
                updateLayoutOperation = CoreDispatcher.INTERNAL_GetCurrentDispatcher().InvokeAsync(UpdateLayout, DispatcherPriority.Render);
#endif
            }
        }
Example #3
0
 public RunOnceToken(DispatcherOperation operation)
 {
     if (operation != null &&
         operation.Status != DispatcherOperationStatus.Completed &&
         operation.Status != DispatcherOperationStatus.Aborted)
     {
         _operation            = operation;
         _operation.Completed += OnCompletedOrAborted;
         _operation.Aborted   += OnCompletedOrAborted;
     }
 }
 /// <summary>
 /// 检测当前是否正在执行操作,并发出提示。
 /// </summary>
 /// <param name="showWarning">是否发出提示。</param>
 /// <returns>当前是否正在执行操作。</returns>
 private bool isInOperation(bool showWarning = true)
 {
     if (this.TaskbarItemInfo.ProgressState == TaskbarItemProgressState.None)
     {
         return(false);
     }
     if (showWarning && (this.showMessageBox == null || this.showMessageBox.Status == DispatcherOperationStatus.Completed))
     {
         this.showMessageBox = this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(Properties.Resources.HintWait, this.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation)));
     }
     return(true);
 }
        protected override void Reprioritize(DispatcherOperation op, DispatcherPriority oldpriority)
        {
            int          oldp = (int)oldpriority;
            PokableQueue q    = this.priorityQueues[oldp];

            lock (q)
            {
                q.Remove(op);
            }

            this.Queue(op.Priority, op);
        }
    public void Invoke(Dispatcher dispatcher)
    {
        List <DispatcherOperation> operations = new List <>();

        for (int i = 0; i < _delegates.Length; i++)
        {
            DispatcherOperation operation = dispatcher.BeginInvoke(_delegates[i], _parameters[i]);
            operations.Add(operation);
        }

        // check status of all operations before completion
    }
Example #7
0
        public void DoEvents()
        {
            DispatcherFrame     nestedFrame   = new DispatcherFrame();
            DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, exitFrameCallback, nestedFrame);

            Dispatcher.PushFrame(nestedFrame);
            if (exitOperation.Status !=
                DispatcherOperationStatus.Completed)
            {
                exitOperation.Abort();
            }
        }
        private void QueueRenderText()
        {
            if (CurrentDispatcherOperation != null)
            {
                CurrentDispatcherOperation.Abort();
            }

            CurrentDispatcherOperation = Dispatcher.BeginInvoke(RenderTextAction, DispatcherPriority.Render, null);

            CurrentDispatcherOperation.Aborted   += (o, e) => { CurrentDispatcherOperation = null; };
            CurrentDispatcherOperation.Completed += (o, e) => { CurrentDispatcherOperation = null; };
        }
Example #9
0
        private void OnGetContext(HttpListenerContext context, Exception error)
        {
            if (!_dispatcher.CheckAccess())
            {
                DispatcherOperation op = _dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => OnGetContext(context, error)));
                Thread.Sleep(100);
                op.Wait();
                return;
            }

            UrlDetails url = new UrlDetails(context.Request.RawUrl);
        }
        private void Scanner_evAdvertisementReceived(ElaTagClassLibrary.ElaTags.Interoperability.ElaBaseData device)
        {
            var formattedData = $"{device.timestamp};" +
                                $"{device.macaddress};" +
                                $"{device.localname};" +
                                $"{device.rssi};";

            DispatcherOperation op = Dispatcher.BeginInvoke((Action)(() =>
            {
                this.lvBleDevice.Items.Add(formattedData);
            }));
        }
 /// <summary>
 ///
 /// </summary>
 public DPFCanvas()
 {
     this.updateAndRenderAction    = this.UpdateAndRender;
     this.updateAndRenderOperation = null;
     this.renderTimer          = new Stopwatch();
     this.MaxRenderingDuration = TimeSpan.FromMilliseconds(20.0);
     this.Loaded            += this.OnLoaded;
     this.Unloaded          += this.OnUnloaded;
     this.ClearColor         = global::SharpDX.Color.Gray;
     this.IsShadowMapEnabled = false;
     this.IsMSAAEnabled      = true;
 }
Example #12
0
        // Waits for a DispatcherOperation to complete.
        // Stops waiting if the proxy is done (disposed or error).
        private bool _WaitForOperation(DispatcherOperation op)
        {
            while (DispatcherOperationStatus.Completed != op.Wait(TimeSpan.FromMilliseconds(500)))
            {
                if (this.IsControllerProxyDone)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #13
0
 void VisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if ((bool)e.NewValue == true)
     {
         result = Dispatcher.BeginInvoke(
             DispatcherPriority.ContextIdle,
             new Action(delegate()
         {
             this.ArcContainer.Focus();
         }));
     }
 }
Example #14
0
        internal void Request(object arg)
        {
            if (_operation == null)
            {
                Debug.Assert(_callback != null);

                _operation =
                    Dispatcher.CurrentDispatcher.BeginInvoke(
                        DispatcherPriority.Loaded,
                        new DispatcherOperationCallback(DispatcherOperation), arg);
            }
        }
Example #15
0
 /// <summary>
 ///
 /// </summary>
 public DPFCanvas()
 {
     updateAndRenderAction    = UpdateAndRender;
     updateAndRenderOperation = null;
     renderTimer          = new Stopwatch();
     MaxRenderingDuration = TimeSpan.FromMilliseconds(20.0);
     Loaded            += OnLoaded;
     Unloaded          += OnUnloaded;
     ClearColor         = global::SharpDX.Color.Gray;
     IsShadowMapEnabled = false;
     IsMSAAEnabled      = true;
 }
Example #16
0
        /// <summary>
        ///     Requests that a new DispatcherOperation be placed on the Dispatcher queue
        /// </summary>
        /// <param name="arg">The object to send the callback in its arg parameter.</param>
        internal void Request(object arg)
        {
            if (_operation != null)
            {
                Cancel();
            }

            _operation = Dispatcher.CurrentDispatcher.BeginInvoke(
                DispatcherPriority.Background,
                new DispatcherOperationCallback(DispatcherOperation),
                arg);
        }
Example #17
0
        public void TestDispatcherOpOnThread()
        {
            Thread     t = new Thread(new ThreadStart(thread));
            Dispatcher d = Dispatcher.CurrentDispatcher;

            t.Start();
            op = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate {
                Console.WriteLine("Some methods");
            });
            wait.Set();
            wait2.WaitOne();
        }
Example #18
0
    public void Dispose()
    {
        var operation = _operation;

        if (operation == null)
        {
            return;
        }
        _operation           = null;
        operation.Completed -= OnCompletedOrAborted;
        operation.Aborted   -= OnCompletedOrAborted;
    }
Example #19
0
 /// <summary>
 /// Executes the specified delegate synchronously on the thread the Dispatcher is associated with.
 /// </summary>
 public void Invoke(Delegate d, object args)
 {
     if (CheckAccess())
     {
         DispatcherOperation.Invoke(d, args);
     }
     else
     {
         DispatcherOperation operation = AddOperation(d, args, new AutoResetEvent(false));
         operation.Wait();
     }
 }
Example #20
0
 /// <summary>
 ///     Moves the window back to its original position.
 ///     Used to provide feedback that panning has hit an edge.
 /// </summary>
 /// <param name="animateBack">Whether to animate or snap back to the original position</param>
 public void EndPanningFeedback(bool animateBack)
 {
     if (_hwndSource != null && _isProvidingPanningFeedback)
     {
         _isProvidingPanningFeedback = false;
         if (_updatePanningOperation != null)
         {
             _updatePanningOperation.Abort();
             _updatePanningOperation = null;
         }
         UnsafeNativeMethods.EndPanningFeedback(Handle, animateBack);
     }
 }
Example #21
0
 private object DispatcherOperation(object arg)
 {
     try
     {
         Debug.Assert(_operation != null && _operation.Status == DispatcherOperationStatus.Executing);
         _callback(arg);
     }
     finally
     {
         _operation = null;
     }
     return(null);
 }
Example #22
0
        private void RaisePropertyChangedEventBody(DependencyPropertyChangedEventArgs e, ChangeType changeType)
        {
            if (propertyChangedCounter > 0)
            {
                return;
            }

            propertyChangedCounter++;
            RaisePropertyChanged(ExtendedPropertyChangedEventArgs.FromDependencyPropertyChanged(e), changeType);
            propertyChangedCounter--;

            notifyOperation = null;
        }
Example #23
0
        /// <summary>
        ///
        /// </summary>
        private async void PositionTask()
        {
            if (m_operation != null && m_operation.Status != DispatcherOperationStatus.Completed)
            {
                m_operation.Abort();
            }

            await Task.Delay(800);

            m_operation = Application.Current.Dispatcher.BeginInvoke(
                new Action(() => StartValidation()),
                DispatcherPriority.Background);
        }
        public static void DoInvoke(Delegate delegateItem, params object[] parameter)
        {
            DispatcherOperation op =
                Dispatcher.CurrentDispatcher.BeginInvoke(delegateItem,
                                                         DispatcherPriority.Background, parameter);


            while (op.Status != DispatcherOperationStatus.Completed)
            {
                System.Windows.Forms.Application.DoEvents();
                //DoEvents();
            }
        }
        /************************************************************************************************************************************/
        /* Private Methods */
        /************************************************************************************************************************************/

        /// <summary>
        /// Notifies all currently queued nodes.
        /// </summary>
        private void NotifyNodes()
        {
            BusNode node;

            while (_updatedNodes.Count > 0)
            {
                //Debug.WriteLine("Notifying nodes.");
                node = (BusNode)_updatedNodes.Dequeue();
                Notify(node);
            }

            _notification = null;
        }
Example #26
0
        public static void DoEvents()
        {
            var frame = new DispatcherFrame();
            DispatcherOperation dispatcherOperation =
                Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, ExitFrameCallback, frame);

            Dispatcher.PushFrame(frame);
            if (dispatcherOperation.Status == DispatcherOperationStatus.Completed)
            {
                return;
            }
            dispatcherOperation.Abort();
        }
 public void NotifyCollectionChanged()
 {
     //OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
     if (_lastDispatcherOperation != null)
     {
         //Pending: The operation is pending and is still in the System.Windows.Threading.Dispatcher queue.
         if (_lastDispatcherOperation.Status == DispatcherOperationStatus.Pending)
         {
             return;
         }
     }
     _lastDispatcherOperation = ApplicationDispatcher.BeginInvoke(DispatcherPriority.Background, OnCollectionChanged, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
 }
 /// <summary>
 /// Queues a node to be notified
 /// </summary>
 /// <param name="node">The node to call the listeners for.</param>
 public void QueueNotification(BusNode node)
 {
     if (!_updatedNodes.Contains(node))
     {
         //Debug.WriteLine("Queueing notification...");
         _updatedNodes.Enqueue(node);
     }
     // add the node to the queue and start the notifier if neccessary.
     if (_notification == null)
     {
         _notification = _dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(NotifyNodes));
     }
 }
 /// <summary>
 /// Handles the ExportCalculated event of the exporter control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="TheBoxSoftware.Documentation.Exporting.ExportCalculatedEventArgs"/> instance containing the event data.</param>
 private void exporter_ExportCalculated(object sender, ExportCalculatedEventArgs e)
 {
     DispatcherOperation op = this.Dispatcher.BeginInvoke(
         DispatcherPriority.Normal,
         new Action <ExportCalculatedEventArgs>(
             p => {
         this.progressIndicator.Value   = 0;
         this.progressIndicator.Minimum = 0;
         this.progressIndicator.Maximum = p.NumberOfSteps;
         this.progressText.Text         = "Started export";
     }),
         e);
 }
 private void CreateThreadForCancelJob(object jobId)
 {
     try
     {
         TranslationJob.CancelJob(cc, new Guid((string)jobId));
         cc.ExecuteQuery();
         DispatcherOperation dop = Dispatcher.BeginInvoke(new Action <string>(PrintResult), "Done");
     }
     catch (Exception e)
     {
         DispatcherOperation dop = Dispatcher.BeginInvoke(new Action <string>(PrintResult), e.ToString());
     }
 }
Example #31
0
 static DispatcherOperation()
 {
     Default = new DispatcherOperation();
 }
Example #32
0
 /// <summary>
 ///     Constructs an instance of the DispatcherHookEventArgs class.
 /// </summary>
 /// <param name="operation">
 ///     The operation in question.
 /// </param>
 public DispatcherHookEventArgs(DispatcherOperation operation)
 {
     _operation = operation;
 }