In some class I want to load 2 collections asynchronously using Task and stop busyindicator
I'm trying something like this
var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
WaitingIndicatorViewModel.IsBusy = true;
var loadData1 = new Task<ObservableCollection<Data1>>(GetData1FromService).ContinueWith(t => Data1Collection = t.Result, uiScheduler);
var loadData2 = new Task<ObservableCollection<Data2>>(GetData2FromService).ContinueWith(t => Data2Collection = t.Result, uiScheduler);
Task.Factory.StartNew(() =>{
loadData1.Start();
loadData2.Start();
Task.WaitAll(loadData1, loadData2);
})
.ContinueWith(o => WaitingIndicatorViewModel.IsBusy = false, uiScheduler);
But this exception excludes InvalidOperationException:Start may not be called on a continuation task.
Why does this not work, and how can I start the continue task after completing both tasks without blocking the current thread?
source
share