WPF实现DoEvents

代码:

public static void DoEvents(Dispatcher dispatcher)
{
    DispatcherFrame frame = new DispatcherFrame();
    dispatcher.BeginInvoke(new Action<object>((obj) =>
    {
        DispatcherFrame frm = obj as DispatcherFrame;
        frm.Continue = false;
    }), DispatcherPriority.Background, frame);
    Dispatcher.PushFrame(frame);
}
View Code

如何使用:

this.Dispatcher.BeginInvoke(new Action(() =>
{
    while (true)
    {
        double dd = Math.PI * Math.PI;
        ThreadHelper.DoEvents(this.Dispatcher);
    }
}));
View Code

 

posted @ 2019-05-27 15:53  0611163  阅读(425)  评论(0编辑  收藏  举报