Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12876170
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: C#/.net

2016-01-15 18:44:59


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Threading;

  7. namespace DrawWpf
  8. {
  9.     class WpfApplication : Application
  10.     {
  11.         private static DispatcherOperationCallback mExitFrameCallback = new DispatcherOperationCallback(ExitFrame);

  12.         private static Object ExitFrame(Object state)
  13.         {
  14.             DispatcherFrame frame = state as DispatcherFrame;
  15.             // Exit the nested message loop.
  16.             frame.Continue = false;
  17.             return null;
  18.         }

  19.         ///
  20.         /// Processes all UI messages currently in the message queue.
  21.         ///
  22.         public static void DoEvents()
  23.         {
  24.             // Create new nested message pump.
  25.             DispatcherFrame nestedFrame = new DispatcherFrame();

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

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

  34.             // If the "exitFrame" callback doesn't get finished, Abort it.
  35.             if (exitOperation.Status != DispatcherOperationStatus.Completed)
  36.                 exitOperation.Abort();
  37.         }
  38.     }
  39. }

用法:

WpfApplication.DoEvents();

修改并转自博客:

http://blog.csdn.net/limlimlim/article/details/7754553
阅读(2486) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~