Ejemplo n.º 1
0
        /// <summary>Waits for the task to complete execution, pumping in the meantime.</summary>
        /// <param name="task">The task for which to wait.</param>
        /// <remarks>This method is intended for usage with Windows Presentation Foundation.</remarks>
        public static T WaitWithPumping <T>(this Task <T> task)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            DispatcherFrame nestedFrame = new DispatcherFrame();

            task.ContinueWith <bool>((Task <T> _) => nestedFrame.Continue = false);
            Dispatcher.PushFrame(nestedFrame);
            return(task.Result);
        }
Ejemplo n.º 2
0
        public void DoEvents()
        {
            Thread.Sleep(0);
            DispatcherFrame frame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
                                                     new DispatcherOperationCallback((o) => {
                ((DispatcherFrame)o).Continue = false;
                return(null);
            }), frame);
            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 3
0
        private static void ProcessUITasks()
        {
            var frame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(
                                                         delegate
            {
                frame.Continue = false;
                return(null);
            }), null);
            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 4
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();
            }
        }
        static object Execute(Action<int> func, int amount)
        {
            var frame = new DispatcherFrame();
            new Thread(() =>
            {
                func.Invoke(amount);
                frame.Continue = false;
            }).Start();
            Dispatcher.PushFrame(frame);

            return Dispatcher.Yield();
        }
Ejemplo n.º 6
0
        public static void DoEvents()
        {
            DispatcherFrame outerFrame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke((SendOrPostCallback) delegate(object arg)
            {
                DispatcherFrame innerFrame = arg as DispatcherFrame;
                innerFrame.Continue        = false;
            }, DispatcherPriority.Background, outerFrame);

            Dispatcher.PushFrame(outerFrame);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Runs a single queued action that was scheduled on the current dispatcher using <see cref="Dispatcher.BeginInvoke(Delegate, DispatcherPriority, object[])"/>
        /// </summary>
        /// <param name="priority">The priority in which the action was scheduled</param>
        private static void RunAsyncAction(DispatcherPriority priority = DispatcherPriority.ContextIdle)
        {
            DispatcherFrame frame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(priority,
                                                     new DispatcherOperationCallback(f =>
            {
                ((DispatcherFrame)f).Continue = false;
                return(null);
            }), frame);
            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 8
0
        public void Await(HouseDelegate method)
        {
            var frame = new DispatcherFrame();

            this.Post(() =>
            {
                method();
                frame.Continue = false;
            });

            Dispatcher.PushFrame(frame); // start the secondary dispatcher, pausing this code
        }
Ejemplo n.º 9
0
        private static void WaitFor(TimeSpan time, DispatcherPriority priority)
        {
            DispatcherTimer timer = new DispatcherTimer(priority);

            timer.Tick    += new EventHandler(OnDispatched);
            timer.Interval = time;
            DispatcherFrame dispatcherFrame = new DispatcherFrame(false);

            timer.Tag = dispatcherFrame;
            timer.Start();
            Dispatcher.PushFrame(dispatcherFrame);
        }
Ejemplo n.º 10
0
        public static void DoEvents()
        {
            var frame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
                                                     new DispatcherOperationCallback(dispatcherFrame =>
            {
                ((DispatcherFrame)dispatcherFrame).Continue = false;
                return(null);
            }), frame);
            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 11
0
        public static void wait(double seconds)
        {
            var frame = new DispatcherFrame();

            new Thread((ThreadStart)(() =>
            {
                Thread.Sleep(TimeSpan.FromSeconds(seconds));
                frame.Continue = false;
            })).Start();

            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 12
0
        public void ProcessUITasks()
        {
            var frame = new DispatcherFrame();

            this.Dispatcher.Invoke(DispatcherPriority.Background, new DispatcherOperationCallback(delegate(object parameter)
            {
                frame.Continue = false;
                return(null);
            }), null);

            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Synchronously processes all work items in the current dispatcher queue.
        /// </summary>
        /// <param name="minimumPriority">
        /// The minimum priority.
        /// All work items of equal or higher priority will be processed.
        /// </param>
        public static void ProcessWorkItems(DispatcherPriority minimumPriority)
        {
            var frame = new DispatcherFrame();

            // Queue a work item.
            Dispatcher.CurrentDispatcher.BeginInvoke(
                minimumPriority, exitFrameCallback, frame);

            // Force the work item to run.
            // All queued work items of equal or higher priority will be run first.
            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 14
0
        void ThreadProc()
        {
            //create second window in background thread
            Window window2 = new Window2();

            window2.Show();

            //start WPF message loop
            DispatcherFrame frame = new DispatcherFrame();

            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 15
0
        public static void DoEvents(Dispatcher disp = null)
        {
            DispatcherFrame frame = new DispatcherFrame();

            if (disp == null)
            {
                disp = Dispatcher.CurrentDispatcher;
            }

            disp.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 16
0
        private void performFieldUpdate()
        {
            DispatcherFrame dispatcherFrame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new DispatcherOperationCallback(delegate(object parameter)
            {
                dispatcherFrame.Continue = false;
                return(null);
            }), null);
            Dispatcher.PushFrame(dispatcherFrame);
            Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
        }
Ejemplo n.º 17
0
        public static void ForceUIToUpdate()
        {
            var frame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new DispatcherOperationCallback(delegate
            {
                frame.Continue = false;
                return(null);
            }), null);

            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 18
0
        public static void DoEvents()
        {
            DispatcherFrame frame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
                                                     new DispatcherOperationCallback(ExitFrames), frame);

            try {
                Dispatcher.PushFrame(frame);
            } catch (InvalidOperationException) {
            }
        }
        public static void DoEvents()
        {
            DispatcherFrame frame = new DispatcherFrame(true);

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
                                                     (SendOrPostCallback) delegate(object arg)
            {
                var f      = arg as DispatcherFrame;
                f.Continue = false;
            }, frame);
            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 20
0
        /// <summary>Waits for the task to complete execution, pumping in the meantime.</summary>
        /// <param name="task">The task for which to wait.</param>
        /// <remarks>This method is intended for usage with Windows Presentation Foundation.</remarks>
        public static void WaitWithPumping(this Task task)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            var nestedFrame = new DispatcherFrame();

            task.ContinueWith(_ => nestedFrame.Continue = false);
            Dispatcher.PushFrame(nestedFrame);
            task.Wait();
        }
Ejemplo n.º 21
0
            private static void WaitFor(DispatcherPriority priority)
            {
                DispatcherTimer timer = new DispatcherTimer(priority);

                timer.Tick += new EventHandler(OnDispatched);
                DispatcherFrame dispatcherFrame = new DispatcherFrame(false);

                timer.Tag = dispatcherFrame;
                timer.Start();
                Dispatcher.PushFrame(dispatcherFrame);
                //((DispatcherObject)this).Dispatcher.PushFrame(dispatcherFrame);
            }
Ejemplo n.º 22
0
            private static void DoEvents()
            {
                DispatcherFrame f = new DispatcherFrame();

                Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
                                                         (SendOrPostCallback) delegate(object arg)
                {
                    DispatcherFrame fr = arg as DispatcherFrame;
                    fr.Continue        = false;
                }, f);
                Dispatcher.PushFrame(f);
            }
Ejemplo n.º 23
0
        protected virtual void doBackgroundGuiThreadWork()
        {
            m_WaitWindow = createWindow();
            m_WaitWindow.Show(m_Left, m_Top, m_Width, m_Height);
            m_WaitWindowShownEvent.Set();

            Dispatcher      dispatcher = m_WaitWindow.DispatcherInstance;
            DispatcherFrame frame      = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(exitFrame), frame);
            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 24
0
        private static void UpdateUI()
        {
            DispatcherFrame frame = new DispatcherFrame();

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new DispatcherOperationCallback(delegate(object parameter)
            {
                frame.Continue = false;
                return(null);
            }
                                                                                                                ), null);
            Dispatcher.PushFrame(frame);
        }
        public static void NonBlockingSleep(int timeInMilliseconds)
        {
            DispatcherFrame df = new DispatcherFrame();

            new Thread((ThreadStart)(() =>
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(timeInMilliseconds));
                df.Continue = false;
            })).Start();

            Dispatcher.PushFrame(df);
        }
Ejemplo n.º 26
0
        public void DoEvents()
        {
            var disp = GetDispatcher();

            if (disp != null)
            {
                DispatcherFrame frame = new DispatcherFrame();
                disp.BeginInvoke(DispatcherPriority.Background,
                                 new DispatcherOperationCallback(ExitFrame), frame);
                Dispatcher.PushFrame(frame);
            }
        }
Ejemplo n.º 27
0
        }         // func RunServerReportAsync

        /// <summary></summary>
        /// <param name="frame"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public IDisposable BlockAllUI(DispatcherFrame frame, string message = null)
        {
            Thread.Sleep(200);             // wait for finish
            if (frame.Continue)
            {
                return(null);                // block ui
            }
            else
            {
                return(null);
            }
        }         // proc BlockAllUI
Ejemplo n.º 28
0
        public static void DoEvents()
        {
            DispatcherFrame frame    = new DispatcherFrame();
            var             callback = new DispatcherOperationCallback(obj =>
            {
                ((DispatcherFrame)obj).Continue = false;
                return(null);
            });

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, callback, frame);
            Dispatcher.PushFrame(frame);
        }
Ejemplo n.º 29
0
 private static TResult PushFrame <TResult>(IDispatcherService dispatcher, Func <Task <TResult> > task)
 {
     return(dispatcher.Invoke(() =>
     {
         var frame = new DispatcherFrame();
         var frameTask = task().ContinueWith(x => { frame.Continue = false; return x.Result; });
         ComponentDispatcher.PushModal();
         Dispatcher.PushFrame(frame);
         ComponentDispatcher.PopModal();
         return frameTask.Result;
     }));
 }
Ejemplo n.º 30
0
        public static void DoEvents()
        {
            var frame = new DispatcherFrame(true);

            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Loaded,
                                                     (SendOrPostCallback)(arg =>
            {
                var f = (DispatcherFrame)arg;
                f.Continue = false;
            }), frame);
            Dispatcher.PushFrame(frame);
        }
 public void DomainCollection_AddDomainObjectFromWorkerThread()
 {
     var dispatcher = Dispatcher.CurrentDispatcher;
     var frame = new DispatcherFrame();
     var workerTask = new Task<bool>(() =>
     {
         
     });
     Dispatcher.PushFrame(frame);
     Assert.IsTrue(raisedCollectionChanged, "CollectionChanged event not raised.");
 }