Loading data in asynchronous methods
While we’ve explored asynchronous data loading techniques in earlier recipes, it’s difficult to ignore this topic in this chapter on performance. Data loading operations often have one of the most significant impacts in real applications.
The concept of this recipe is straightforward: instead of loading data in the view model (or view) constructor, we will load it asynchronously when the view is displayed. We’ll create a simple view model that initiates the data-loading process as the page becomes visible.
Getting ready
To follow the steps described in this recipe, we just need to create a blank .NET MAUI application.
The code for this recipe is available at https://github.com/PacktPublishing/.NET-MAUI-Cookbook/tree/main/Chapter08/c8-AsyncLoading.
How to do it…
Let’s create a simple view that displays a couple of properties from a view model and apply a technique we’ve used in several earlier...