Winform 里有 Application.DoEvents();可刷新!
WPF 里没这个,尽管可用委托实现多线程,但是刷新还是不行!
后来找到了 类似App.DoEvents()的方法();
代码:
public partial class App : Application
{
private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame);
public static 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();
}
}
private static Object ExitFrame (Object state)
{
DispatcherFrame frame = state as
DispatcherFrame;
frame.Continue = false;
return null;
}
}
}
DispatcherFrame 的用途就是激活一新的消息循环,并以 Continue 属性作为退出新消息循环的标志。