在WPF中,什么是Windows窗体暂停/ ResumeLayout()和BackgroundWorker的()的equivelent [英] In WPF, what is the equivelent of Suspend/ResumeLayout() and BackgroundWorker() from Windows Forms
问题描述
如果我在$ C $后面℃的功能,我想实现显示在状态栏下面是有道理的正在加载...,但我们知道,从WinForms的是NONO:
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的()的equivelent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!