谁能告诉我 if 和 else 语句在这个函数中是如何相关的。我正在将来自另一个线程的文本显示到 GUI 线程。执行的顺序或方式是什么。else 语句是否必要?
delegate void SetTextCallback(string text);
private void SetText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.textBox7.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.textBox7.Text = text;
}
}