当页面出现在我的 Xamarin.Forms 项目中时,我有一个 AppearingCommand 调用,它最终执行以下 sqlite-net-pcl 行:(我已经有一个处理加载时间的机制)
AppearingCommand = new Command( async() => {
//...
var data = await db.Table<PlantCategory>().ToListAsync();
//...
}
我想将此方法移动到构造函数,但我不能这样做,因为如果它同步执行它会挂起:
ctor() {
//...
var data = db.Table<PlantCategory>().ToListAsync().Result;
//...
}
该行永远不会返回(我猜是因为死锁或其他原因)。如果我想在构造函数中执行这一行,我还有哪些其他选择?