我正在使用Winform应用程序。 Method
由一个BackgroundWorker线程启动。对不起。我之前没有提到这一点。从任务更新UI标签。继续
private void Method()
{
tasks[i] = Task.Factory
.StartNew(() => fileProcessor.ProcessEachMachine(mdetail))
.ContinueWith(UpdateLabel, TaskContinuationOptions.OnlyOnRanToCompletion);
}
我有一个长时间的运行功能ProcessEachMachine
。在继续功能UpdateLabel
我想访问UIlabel并更新状态。
private void UpdateLabel()
{
progressLbl.Text = "updated";
}
但标签没有更新。如何访问UILabel并更新它的文本。
确定'ProcessEachMachine'之前完成更新标签?也许任务运行很长时间,很长时间 – GETah 2012-04-23 18:11:06
ContinueWith是什么保证?假设我错了吗? – Sandeep 2012-04-23 18:12:22
@Sandeep不,你没有错。你只需要确保你回到UI线程。 – Servy 2012-04-23 18:19:41