DoEvents WPF
here is the common code for having DoEvents() function for WPF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#region DoEvents private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame); /// <summary> /// Processes all UI messages currently in the message queue. /// </summary> 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, exitFrameCallback, 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(); } } private static Object ExitFrame(Object state) { DispatcherFrame frame = state as DispatcherFrame; // Exit the nested message loop. frame.Continue = false; return null; } #endregion |
place this in App class and use App.DoEvents();
Commentaires récents