在WPF中,什么是Windows窗体暂停/ ResumeLayout()和BackgroundWorker的()相当于

在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();
}