Hi, I am curious where the best place would be to handle startup tasks that I want to run before MainPage loads. Initially I thought I would place this into OnStart. If you look below, in OnStart I check if a Category table exists, and if it doesn't, I create it. Then I download categories asynchronously with a web API, and insert them into the table. I would like all this to happen before my MainPage loads. However, because I am doing this asynchronously, I don't know if the way I have this coded ensures that it will be completed before my MainPage loads. I'm curious what is the best approach for handling asynchronous startup tasks like this. Any advice would be greatly appreciated.
Thanks!
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
protected async override void OnStart()
{
CategoryDB categoryDB = new CategoryDB();
if (!categoryDB.TableExists())
{
categoryDB.CreateCategoryTable();
await GetCategoryHierarchy();
}
}