可以Application.DoEvents()在C#中使用吗?
这个函数是否能够让GUI跟上应用程序的其余部分,就像VB6 DoEvents一样?
这是MSDN提供的代码,虽然它似乎不清楚它在做什么:
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public void DoEvents()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}
public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
Run Code Online (Sandbox Code Playgroud)
我刚刚注意到今天在DoEvents定义该方法的一些遗留代码中的类似实现。为什么我们需要这个以及将框架推送到调度程序上意味着什么?