當前位置: 首頁>>代碼示例>>C#>>正文


C# Threading.DispatcherFrame類代碼示例

本文整理匯總了C#中System.Windows.Threading.DispatcherFrame的典型用法代碼示例。如果您正苦於以下問題:C# DispatcherFrame類的具體用法?C# DispatcherFrame怎麽用?C# DispatcherFrame使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DispatcherFrame類屬於System.Windows.Threading命名空間,在下文中一共展示了DispatcherFrame類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        private static void Main(string[] args)
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            Console.CancelKeyPress +=
                (sender, e) =>
                {
                    e.Cancel = true;
                    cts.Cancel();
                };

            // Since Console apps do not have a SyncronizationContext, we're leveraging the built-in support
            // in WPF to pump the messages via the Dispatcher.
            // See the following for additional details:
            //   http://blogs.msdn.com/b/pfxteam/archive/2012/01/21/10259307.aspx
            //   https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/1362
            SynchronizationContext previousContext = SynchronizationContext.Current;
            try
            {
                var context = new DispatcherSynchronizationContext();
                SynchronizationContext.SetSynchronizationContext(context);

                DispatcherFrame dispatcherFrame = new DispatcherFrame();
                Task mainTask = MainAsync(args, cts.Token);
                mainTask.ContinueWith(task => dispatcherFrame.Continue = false);

                Dispatcher.PushFrame(dispatcherFrame);
                mainTask.GetAwaiter().GetResult();
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(previousContext);
            }
        }
開發者ID:umaranis,項目名稱:StyleCopAnalyzers,代碼行數:33,代碼來源:Program.cs

示例2: DoEvents

        /// <summary>
        /// Processes all UI messages currently in the message queue.
        /// </summary>
        public static void DoEvents()
        {

            // Create new nested message pump.
            DispatcherFrame nestedFrame = new DispatcherFrame();



            // Dispatch a callback to the current message queue, when getting called, 
            // this callback will end the nested message loop.
            // note that the priority of this callback should be lower than the that of UI event messages.
            DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(
                                                  DispatcherPriority.Background, exitFrameCallback, nestedFrame);



            // pump the nested message loop, the nested message loop will 
            // immediately process the messages left inside the message queue.
            Dispatcher.PushFrame(nestedFrame);



            // If the "exitFrame" callback doesn't get finished, Abort it.
            if (exitOperation.Status != DispatcherOperationStatus.Completed)
            {
                exitOperation.Abort();
            }

        }
開發者ID:mousetwentytwo,項目名稱:test,代碼行數:32,代碼來源:WpfApplication.cs

示例3: DoEvents

 public static void DoEvents()
 {
     DispatcherFrame frame = new DispatcherFrame();
     Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
         new DispatcherOperationCallback(ExitFrame), frame);
     Dispatcher.PushFrame(frame);
 }
開發者ID:RonnChyran,項目名稱:Soft64-Bryan,代碼行數:7,代碼來源:DispatcherUtil.cs

示例4: CountUploadedFiles

        public void CountUploadedFiles(int counter, bool result, string fileName)
        {
            #region Needed for counter
            var dispatcherFrame = new DispatcherFrame(true);
            Dispatcher.CurrentDispatcher.BeginInvoke
            (
            DispatcherPriority.Background,
            (SendOrPostCallback)delegate(object arg)
            {
                var f = arg as DispatcherFrame;
                if (f != null) f.Continue = false;
            },
            dispatcherFrame
            );
            Dispatcher.PushFrame(dispatcherFrame);
            #endregion
            if (result)
            {

                textBlockCounter.Text = counter.ToString(CultureInfo.InvariantCulture) + " / " + _theImages.Count;
                if (fileName != "")
                    labelCopyingStatus.Content = "Copying " + fileName;
                else
                    labelCopyingStatus.Content = "";
            }
            else
                textBlockCounter.Text = counter.ToString(CultureInfo.InvariantCulture);
        }
開發者ID:jessetinell,項目名稱:Imgu,代碼行數:28,代碼來源:MainMenu.xaml.cs

示例5: Fail

		public override void Fail(string message, string detailMessage)
		{
			base.Fail(message, detailMessage); // let base class write the assert to the debug console
			string stackTrace = "";
			try {
				stackTrace = new StackTrace(true).ToString();
			} catch {}
			lock (ignoredStacks) {
				if (ignoredStacks.Contains(stackTrace))
					return;
			}
			if (!dialogIsOpen.Set())
				return;
			if (!SD.MainThread.InvokeRequired) {
				// Use a dispatcher frame that immediately exits after it is pushed
				// to detect whether dispatcher processing is suspended.
				DispatcherFrame frame = new DispatcherFrame();
				frame.Continue = false;
				try {
					Dispatcher.PushFrame(frame);
				} catch (InvalidOperationException) {
					// Dispatcher processing is suspended.
					// We currently can't show dialogs on the UI thread; so use a new thread instead.
					new Thread(() => ShowAssertionDialog(message, detailMessage, stackTrace, false)).Start();
					return;
				}
			}
			ShowAssertionDialog(message, detailMessage, stackTrace, true);
		}
開發者ID:Paccc,項目名稱:SharpDevelop,代碼行數:29,代碼來源:SDTraceListener.cs

示例6: ExecuteWithDispatcher

        public static void ExecuteWithDispatcher(Action<Dispatcher, Action> testBodyDelegate,
            int timeoutMilliseconds = 20000, string timeoutMessage = "Test did not complete in the spefied timeout")
        {
            var uiThreadDispatcher = Dispatcher.CurrentDispatcher;
            //ThreadingHelpers.UISynchronizationContext = new DispatcherSynchronizationContext(uiThreadDispatcher);

            var frame = new DispatcherFrame();

            // Set-up timer that will call Fail if the test is not completed in specified timeout

            TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

            if (Debugger.IsAttached)
            {
                timeout = TimeSpan.FromDays(1);
            }

            Observable.Timer(timeout)
                .Subscribe(
                    _ => { uiThreadDispatcher.BeginInvoke(new Action(() => { Assert.True(false, timeoutMessage); })); });

            // Shedule the test body with current dispatcher (UI thread)
            uiThreadDispatcher.BeginInvoke(
                new Action(() => { testBodyDelegate(uiThreadDispatcher, () => { frame.Continue = false; }); }));

            // Run the dispatcher loop that will execute the above logic
            Dispatcher.PushFrame(frame);
        }
開發者ID:pglazkov,項目名稱:MvvmValidation,代碼行數:28,代碼來源:TestUtil.cs

示例7: DispatchFrame

 public static void DispatchFrame(DispatcherPriority priority = DispatcherPriority.Background)
 {
     DispatcherFrame frame = new DispatcherFrame();
     Dispatcher.CurrentDispatcher.BeginInvoke(priority,
         new DispatcherOperationCallback((f)=>((DispatcherFrame)f).Continue = false), frame);
     Dispatcher.PushFrame(frame);
 }
開發者ID:SonarSource-VisualStudio,項目名稱:sonarlint-visualstudio,代碼行數:7,代碼來源:DispatcherHelper.cs

示例8: DoEvents

        /// <summary>現在メッセージ待ち行列の中にある全UIメッセージを処理する</summary>
        private void DoEvents()
        {
            // 新しくネスト化されたメッセージ ポンプを作成
            DispatcherFrame frame = new DispatcherFrame();

            // DispatcherFrame (= 実行ループ) を終了させるコールバック
            DispatcherOperationCallback exitFrameCallback = (f) =>
            {
                // ネスト化されたメッセージ ループを抜ける
                ((DispatcherFrame)f).Continue = false;
                return null;
            };

            // 非同期で実行する
            // 優先度を Background にしているので、このコールバックは
            // ほかに処理するメッセージがなくなったら実行される
            DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(
                DispatcherPriority.Background, exitFrameCallback, frame);

            // 実行ループを開始する
            Dispatcher.PushFrame(frame);

            // コールバックが終了していない場合は中斷
            if (exitOperation.Status != DispatcherOperationStatus.Completed)
            {
                exitOperation.Abort();
            }
        }
開發者ID:hirekoke,項目名稱:FloWin,代碼行數:29,代碼來源:App.xaml.cs

示例9: Subscription_push_can_be_dispatched_on_designated_thread_blocking_scenario

        public void Subscription_push_can_be_dispatched_on_designated_thread_blocking_scenario()
        {
            var threadId = -2;
            var threadIdFromTest = -1;
            IBus bus = null;

            var resetEvent = new ManualResetEvent(false);

            var uiThread = new Thread(
                () =>
                    {
                        Helpers.CreateDispatchContext();
                        var frame = new DispatcherFrame();
                        threadId = Thread.CurrentThread.ManagedThreadId;
                        bus = BusSetup.StartWith<RichClientFrontend>().Construct();
                        bus.Subscribe<MessageB>(
                            msg =>
                                {
                                    threadIdFromTest = Thread.CurrentThread.ManagedThreadId;
                                    frame.Continue = false;
                                },
                            c => c.DispatchOnUiThread());
                        resetEvent.Set();
                        Dispatcher.PushFrame(frame);
                    });
            uiThread.Start();
            resetEvent.WaitOne();
            bus.Publish(new MessageB());
            uiThread.Join();
            threadIdFromTest.ShouldBeEqualTo(threadId);
        }
開發者ID:pixelmeister,項目名稱:MemBus,代碼行數:31,代碼來源:When_using_the_bus_in_the_ui.cs

示例10: Open

 public void Open(FrameworkElement container)
 {
     if (container != null)
     {
         _container = container;
         // 通過禁用來模擬模態的對話框
         _container.IsEnabled = false;
         // 保持總在最上
         this.Owner = GetOwnerWindow(container);
         if (this.Owner != null)
         {
             this.Owner.Closing += new System.ComponentModel.CancelEventHandler(Owner_Closing);
         }
         // 通過監聽容器的Loaded和Unloaded來顯示/隱藏窗口
         _container.Loaded += new RoutedEventHandler(Container_Loaded);
         _container.Unloaded += new RoutedEventHandler(Container_Unloaded);
     }
     this.Show();
     try
     {
         ComponentDispatcher.PushModal();
         _dispatcherFrame = new DispatcherFrame(true);
         Dispatcher.PushFrame(_dispatcherFrame);
     }
     finally
     {
         ComponentDispatcher.PopModal();
     }
 }
開發者ID:xdusongwei,項目名稱:ErlangEditor,代碼行數:29,代碼來源:MyDialog.cs

示例11: DoEvents

 public static void DoEvents(DispatcherPriority priority = DispatcherPriority.Background) {
     DispatcherFrame frame = new DispatcherFrame();
     DXSplashScreen.SplashContainer.SplashScreen.Dispatcher.BeginInvoke(
         priority,
         new DispatcherOperationCallback(ExitFrame),
         frame);
     Dispatcher.PushFrame(frame);
 }
開發者ID:JustGitHubUser,項目名稱:DevExpress.Mvvm.Free,代碼行數:8,代碼來源:SplashScreenServiceTests.cs

示例12: DoEvents

 public static void DoEvents(DispatcherPriority nPrio)
 {
     DispatcherFrame nestedFrame = new DispatcherFrame();
     DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(nPrio, exitFrameCallback, nestedFrame);
     Dispatcher.PushFrame(nestedFrame);
     if (exitOperation.Status != DispatcherOperationStatus.Completed)
         exitOperation.Abort();
 }
開發者ID:Slesa,項目名稱:Playground,代碼行數:8,代碼來源:ReportPresenter.cs

示例13: ProcessMessages

        /// <summary>
        /// Waits until all pending messages up to the specified priority are processed.
        /// </summary>
        /// <param name="dispatcher">The dispatcher to wait on.</param>
        /// <param name="priority">The priority up to which all messages should be processed.</param>
        public static void ProcessMessages([NotNull] this Dispatcher dispatcher, DispatcherPriority priority)
        {
            Contract.Requires(dispatcher != null);

            var frame = new DispatcherFrame();
            dispatcher.BeginInvoke(priority, () => frame.Continue = false);
            Dispatcher.PushFrame(frame);
        }
開發者ID:tom-englert,項目名稱:TomsToolbox,代碼行數:13,代碼來源:PresentationFrameworkExtensions.cs

示例14: WaitWithPumping

 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();
 }
開發者ID:Robin--,項目名稱:raml-dotnet-tools,代碼行數:8,代碼來源:TaskExtensions.cs

示例15: DoEvents

 public void DoEvents() {
     var disp = GetDispatcher();
     if (disp != null) {
         DispatcherFrame frame = new DispatcherFrame();
         disp.BeginInvoke(DispatcherPriority.Background,
                 new DispatcherOperationCallback(ExitFrame), frame);
         Dispatcher.PushFrame(frame);
     }
 }
開發者ID:AlexanderSher,項目名稱:RTVS-Old,代碼行數:9,代碼來源:TestShellBase.cs


注:本文中的System.Windows.Threading.DispatcherFrame類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。