-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Text;
-
using System.Windows;
-
using System.Windows.Threading;
-
-
namespace DrawWpf
-
{
-
class WpfApplication : Application
-
{
-
private static DispatcherOperationCallback mExitFrameCallback = new DispatcherOperationCallback(ExitFrame);
-
-
private static Object ExitFrame(Object state)
-
{
-
DispatcherFrame frame = state as DispatcherFrame;
-
// Exit the nested message loop.
-
frame.Continue = false;
-
return null;
-
}
-
-
///
-
/// Processes all UI messages currently in the message queue.
-
///
-
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, mExitFrameCallback, 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();
-
}
-
}
-
}
用法:
WpfApplication.DoEvents();
修改并转自博客:
http://blog.csdn.net/limlimlim/article/details/7754553
阅读(2486) | 评论(0) | 转发(0) |