I have an AppearingCommand called when a Page appears in my Xamarin.Forms project, that eventually executes the following sqlite-net-pcl line: (I already have a mechanism coping with loading time)
AppearingCommand = new Command( async() => {
//...
var data = await db.Table<PlantCategory>().ToListAsync();
//...
}
I want to move this method to the constructor, but I cannot do it, as it hangs if it is executed synchronously:
ctor() {
//...
var data = db.Table<PlantCategory>().ToListAsync().Result;
//...
}
The line never returns (I am guessing because of a deadlock or something). What are other options that I have if I want to execute this line inside the constructor?