在看 MSDN 的时候发现了一段比较实用的代码,能在 WPF 下能执行与System.Windows.Forms.Application.DoEvents方法类似的功能。以下对 MSDN 中的代码进行了微调,微调主要集中在DispatcherPriority.SystemIdle 附近。
Imports System.Security.Permissions
Imports System.Windows.Threading
''' <summary>
''' 处理当前在工作项队列的所有帧。
''' </summary>
<SecurityPermissionAttribute(SecurityAction.Demand,
Flags:=SecurityPermissionFlag.UnmanagedCode)>
Public Sub DoEvents()
Dim frame As New DispatcherFrame()
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, Sub(f As
DispatcherFrame) f.Continue = False, frame)
Dispatcher.PushFrame(frame)
End Sub
