【发布时间】:2013-02-15 18:20:16
【问题描述】:
我有这个:
BusyState.SetBusy("Updating Calendar Data");
Dispatcher.CurrentDispatcher.Invoke(new Action(async () =>
{
// calling "update" will hit servers outside my control and may take time
await PublicCalendars.Update();
await PrivateCalendars.Update();
// clearing the busy state should only happen when both update tasks are finished
BusyState.ClearBusy();
}));
变量 PublicCalendars 和 PrivateCalendars 都扩展了 ObservableCollection 并在调用更新期间填充。集合绑定到某些 WPF GUI,因此必须从 UI 线程添加项目。
我想删除等待并让两个调用同时运行。我怎样才能做到这一点,并且在两个任务都完成后仍然清楚我的忙碌状态?
【问题讨论】:
-
顺便说一句,我认为这里不需要
Dispatcher.CurrentDispatcher.Invoke()。如果CurrentDispatcher返回了正确的dispatcher,说明你在UI线程上,这意味着你可以直接调用所有的方法。
标签: c# .net wpf task-parallel-library c#-5.0