【发布时间】:2018-12-05 01:04:21
【问题描述】:
我正在使用 Xamarin Forms 构建应用程序,我遇到了 DisplayAlert 触发一次但第二次挂起的问题。
请考虑以下代码:
ThisThingClickedCommand = new Command(
async () =>
{
var continue = true;
if (SomeVariable.is_flagged == 0)
{
continue = await PageSent.DisplayAlert("User Question", "This is a question for the user", "Yes", "No");
}
if (continue)
{
Debug.WriteLine("This debug fires");
var AnswerToSecondQuestion = await PageSent.DisplayAlert("Second Question", "This is a second question for the user", "Yes", "No");
if (AnswerToSecondQuestion)
{
// Do more things
}
Debug.WriteLine("This one does not :(");
}
}),
上面的代码已经在一个项目中存在了很长时间,并且似乎一直有效,直到最近更新到 Visual Studio 2017 以及随后的一些新的目标 Windows 版本。
当我在 Windows 上启动应用程序(目前在其他设备上未经测试)并且这段特定的代码运行时,第一个 DisplayAlert 显示没有问题,但第二个 DisplayAlert 从未显示并且应用程序挂起等待它回答(我假设)。
如果有人能解释如何解决这个问题,我将不胜感激,但如果他们也能解释为什么会发生这种情况,那就更好了。
【问题讨论】:
标签: c# xamarin.forms uwp async-await xamarin.uwp