在WPF中,什么是Windows窗体暂停/ ResumeLayout()和BackgroundWorker的()相当于 [英] In WPF, what is the equivalent of Suspend/ResumeLayout() and BackgroundWorker() from Windows Forms

查看:682
本文介绍了在WPF中,什么是Windows窗体暂停/ ResumeLayout()和BackgroundWorker的()相当于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在code后面的功能,我想实现显示在状态栏下面是有道理的正在加载...,但是我们从的WinForms知道是否否:

If I am in a function in the code behind, and I want to implement displaying a "Loading..." in the status bar the following makes sense, but as we know from WinForms is a NoNo:

StatusBarMessageText.Text = "Loading Configuration Settings...";            
LoadSettingsGridData();
StatusBarMessageText.Text = "Done";

从WinForms的第1章类101我们现在都,是窗体不会显示更改用户直到整个功能完成后...这意味着加载的消息不会被显示给用户。需要以下code。

What we all now from WinForms Chapter 1 class 101, is the form won't display changes to the user until after the Entire Function completes... meaning the "Loading" message will never be displayed to the user. The following code is needed.

Form1.SuspendLayout();    
StatusBarMessageText.Text = "Loading Configuration Settings...";                
Form1.ResumeLayout();

LoadSettingsGridData();

Form1.SuspendLayout();    
StatusBarMessageText.Text = "Done";
Form1.ResumeLayout();

什么是这个根本问题在WPF处理的最佳实践?

What is the best practice for dealing with this fundamental issue in WPF?

推荐答案

最佳和最简单的:

using(var d = Dispatcher.DisableProcessing())
{
    /* your work... Use dispacher.begininvoke... */
}

或者

IDisposable d;

Try
{
    d = Dispatcher.DisableProcessing();
    /* your work... Use dispacher.begininvoke... */
} Finally {
    d.Dispose();
}

这篇关于在WPF中,什么是Windows窗体暂停/ ResumeLayout()和BackgroundWorker的()相当于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆