【发布时间】:2017-09-15 08:38:17
【问题描述】:
有什么区别
Application.Current.Dispatcher.Invoke(
new Action(() =>
{
txtRowCount.Text = string.Format("{0}", rowCount);
})
); //end-Invoke
对
Application.Current.Dispatcher.Invoke(
() =>
{
txtRowCount.Text = string.Format("{0}", rowCount);
}
); //end-Invoke
如果编译器抱怨,我会使用另一个,但我不知道到底发生了什么。
【问题讨论】:
-
它们是一样的。第二个 sn-p 中的 lambda 被隐式转换为一个动作。虽然通常相同,但我也建议使用 TextBlock 的调度程序,例如
txtRowCount.Dispatcher.Invoke(() => txtRowCount.Text = string.Format("{0}", rowCount));