I'm try to use Stephen Cleary libray Nito.Mvvm.Async to handle async initialization in my view model but i have some problems with the SyncronisationContext:
Example 1: i'm not sure how to handle errors in a way compatible with unit tests I want to fill a list of program asyncronously but if something get wrong I have to display a popup (in main thread) so i tried this:
ProgramsAsync = NotifyTask.Create(this.FillPrograms());
ProgramsAsync.Task.ContinueWith(previous =>
{
messageBoxService.ShowError(ProgramsAsync.ErrorMessage);
},
CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted,
TaskScheduler.FromCurrentSynchronizationContext());
But the TaskScheduler.FromCurrentSynchronizationContext is invalid in the context of mstest. How to ensure the handling of the error is in the right context ?
Example 2: Sometimes the result of the async method is used to fill a CollectionView. This requires to be in main thread to update values but this time it's not when an error occurs.
Thanks for your help. Mins