做了一个超大矩阵,每个块对应一个对象,数据更新后,界面的数据跟原始数据对不上,不知道为什么,
模拟winform 的Application.DoEvents() 可以解决,不知道大家有没有其他方法,以下是WPF代码,
在频繁变动的地方加上 DoEvents()
/// <summary> /// Simulate Application.DoEvents function of <see cref=" System.Windows.Forms.Application"/> class. /// </summary> [SecurityPermissionAttribute(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) { } //catch (InvalidOperationException ex) //{ //} } private static object ExitFrames(object frame) { ((DispatcherFrame)frame).Continue = false; return null; }