May 2019
Intermediate to advanced
504 pages
11h 50m
English
In the constructor scenario we described previously, let's assume that the constructor of a view-model should retrieve a certain amount of data that will then be used by the methods or commands of the same view-model. If we execute the method without awaiting the result, there is no guarantee that, when the command is executed, the async constructor execution would have completed.
Let's demonstrate this with an abstract example:
public class MyViewModel{ public MyViewModel() { // Can't await the method; MyAsyncMethod(); } private async Task MyAsyncMethod() { // Load data from service to the ViewModel } public async Task ExecuteMyCommand() { // Data from the MyAsyncMethod is required }}
When the ExecuteMyCommand ...
Read now
Unlock full access