0

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

Minskaya
  • 1
  • 1
  • Still in progress: I made a try to provide a SynchronisationContext in the unit test with `SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());` but this 'empty' context does nothing : the awaited task are not called I tried several version of SynchronizationContext found on SO but none of them seems to suit – Minskaya Jun 13 '18 at 08:27
  • No one interested ? – Minskaya Jun 19 '18 at 15:46
  • bump........... – Minskaya Jun 28 '18 at 13:30

0 Answers0