
概述
在WPF中使用DoEvents的方法。
解释
public static class DispatcherHelper { [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] public static void DoEvents() { var frame = new DispatcherFrame(); Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrames), frame); try { Dispatcher.PushFrame(frame); } catch (Exception ex) { //自行处理异常 } } private static object ExitFrames(object frame) { ((DispatcherFrame)frame).Continue = false; return null; } }
本文由 .Net中文网 原创发布,欢迎大家踊跃转载。
转载请注明本文地址:https://www.byteflying.com/archives/3443。