我正在this tutorial
讨论如何在后台执行一些工作,在这段代码中,我对为什么在调用方法reading the file...
之前不显示消息感到困惑。ReadTheFile(filename)
private void btnSelect_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.CheckFileExists = true;
ofd.CheckPathExists = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
lblResults.Text = " ... reading the file ...";
FileReader1 fr = new FileReader1();
int numLines = fr.ReadTheFile(ofd.FileName);
lblResults.Text = string.Format("We read {0} lines", numLines.ToString());
}
}
作者通过以下方式解释它,但它并没有真正让我明白。
Worse, even though we set the label’s Text property before we call ReadTheFile, the message loop doesn’t get a chance to process that change, and update the text, before we go out to lunch in ReadTheFile.
这是什么意思?这可以用更简单的术语来解释吗?