Im using the MvvmCross and AsyncEx library in a Windows 10 application (UWP).
In ViewModel, I have an INotifyTaskCompletion (1) property that is connected to the Async method in ViewModel (2)
In (2), I call the Async library method, which:
- Checks local cache
- Download data asynchronously
- Adds data to the cache
Caching code cannot be made asynchronous, so the library method contains both blocking and asynchronous code.
Q. What is the best way to prevent user interface thread blocking?
I understand from Stephen Cleary not to block asynchronous code and not to use Task.Run in library methods. So I have to ....
Move caching calls to (2), for example.
- Use Task.Run (to check cache)
- call the library method asynchronously
- Use Task.Run again (for data caching)?
Is there a better way?
source share