Assuming ChartViewModels is an ObservableCollection<T>, the following code works as expected:
await Dispatcher.InvokeAsync(() =>
{
ChartViewModels.Clear();
ChartViewModels.AddRange(initializedCharts);
}, DispatcherPriority.DataBind, mCancellationToken.Token);
await UpdateChartsWithValuesAsync(chartsToInitialize, ChartViewModels).ConfigureAwait(false);
Instead, if I wrap the the UpdateChartsWithValuesAsync method call in the ContinueWith delegate, the method is not awaited anymore. I already tried to change the ConfigureAwait(false) to true but nothing seems to change. Below the edited code:
await Dispatcher.InvokeAsync(() =>
{
ChartViewModels.Clear();
ChartViewModels.AddRange(initializedCharts);
}, DispatcherPriority.DataBind, mCancellationToken.Token).Task
.ContinueWith(async t => await UpdateChartsWithValuesAsync(chartsToInitialize, ChartViewModels).ConfigureAwait(false), mCancellationToken.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current).ConfigureAwait(false);
The code into the Dispatcher is always executed before the ContinueWith delegate, but it doesn't await UpdateChartsWithValuesAsync to complete anymore, raising nasty bugs.
Can anyone explain this behaviour? Thanks
WPF, .NET Framework 4.7 project