• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Threading.DispatcherFrame类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Windows.Threading.DispatcherFrame的典型用法代码示例。如果您正苦于以下问题:C# DispatcherFrame类的具体用法?C# DispatcherFrame怎么用?C# DispatcherFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DispatcherFrame类属于System.Windows.Threading命名空间,在下文中一共展示了DispatcherFrame类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: ProcessUITasks

 public static void ProcessUITasks()
 {
     DispatcherFrame frame = new DispatcherFrame();
     Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.ContextIdle, new DispatcherOperationCallback(delegate (object parameter) {
         frame.Continue = false;
         return null;
     }), null);
     Dispatcher.PushFrame(frame);
 }
开发者ID:Kirluu,项目名称:UlrikHovsgaardAlgorithm,代码行数:9,代码来源:SuperViewModel.cs


示例17: DoEvents

 public static void DoEvents(this Dispatcher dispatcher)
 {
     var frame = new DispatcherFrame();
     dispatcher.BeginInvoke(
         DispatcherPriority.Background,
         new DispatcherOperationCallback(ExitFrame),
         frame);
     Dispatcher.PushFrame(frame);
 }
开发者ID:JohanLarsson,项目名称:So.Wpf,代码行数:9,代码来源:DispatcherUtil.cs


示例18: PumpTill

 internal override void PumpTill(Task task)
 {
     if (!task.IsCompleted)
     {
         var frame = new DispatcherFrame();
         task.ContinueWith(_ => frame.Continue = false, TaskScheduler.Default);
         Dispatcher.PushFrame(frame);
     }
 }
开发者ID:AArnott,项目名称:Xunit.StaFact,代码行数:9,代码来源:DispatcherSynchronizationContextAdapter.cs


示例19: WaitWithPumping

 public static void WaitWithPumping(Task task)
 {
     if (task == null) throw new ArgumentNullException("task");
     var nestedFrame = new DispatcherFrame();
     task.ContinueWith(_ => nestedFrame.Continue = false);
     Dispatcher.PushFrame(nestedFrame);
     //execute this loop until all other tasks are done. it won't block the ui thread
     task.Wait();
 }
开发者ID:scottccoates,项目名称:SoPho,代码行数:9,代码来源:App.xaml.cs


示例20: TestDispatcherOrder

		public void TestDispatcherOrder ()
		{
			Dispatcher d = Dispatcher.CurrentDispatcher;

			DispatcherFrame frame = new DispatcherFrame ();
			bool fail = true;
			int next = 1;
			
			d.BeginInvoke (DispatcherPriority.Normal, (Action) delegate {
				if (next != 3)
					throw new Exception ("Expected state 3, got " + next.ToString ());

				next = 4;
				Console.WriteLine ("First");
			});
			d.BeginInvoke (DispatcherPriority.Normal, (Action) delegate {
				if (next != 4)
					throw new Exception ("Expected state 4, got " + next.ToString ());

				next = 5;
				Console.WriteLine ("Second");
			});
			d.BeginInvoke (DispatcherPriority.Send, (Action) delegate {
				if (next != 1)
					throw new Exception ("Expected state 1, got " + next.ToString ());
				next = 2;
				Console.WriteLine ("High Priority");
				d.BeginInvoke (DispatcherPriority.Send, (Action) delegate {
					if (next != 2)
						throw new Exception ("Expected state 2, got " + next.ToString ());

					next = 3;
					Console.WriteLine ("INSERTED");
				});
			});
			d.BeginInvoke (DispatcherPriority.SystemIdle, (Action) delegate {
				if (next != 6)
					throw new Exception ("Expected state 6, got " + next.ToString ());
				
				Console.WriteLine ("Idle");
				frame.Continue = false;
				fail = false;
			});
			
			d.BeginInvoke (DispatcherPriority.Normal, (Action) delegate {
				if (next != 5)
					throw new Exception ("Expected state 5, got " + next.ToString ());
				next = 6;
				Console.WriteLine ("Last normal");
			});
			
			Dispatcher.PushFrame (frame);

			if (fail)
				throw new Exception ("Expected all states to run");
		}
开发者ID:nobled,项目名称:mono,代码行数:56,代码来源:DispatcherTest.cs



注:本文中的System.Windows.Threading.DispatcherFrame类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Threading.DispatcherOperation类代码示例发布时间:2022-05-26
下一篇:
C# Threading.Dispatcher类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap