我有这个代码:
private async void ContextMenuForGroupRightTapped(object sender, RightTappedRoutedEventArgs args)
{
CheckBox ckbx = null;
if (sender is CheckBox)
{
ckbx = sender as CheckBox;
}
if (null == ckbx)
{
return;
}
string groupName = ckbx.Content.ToString();
var contextMenu = new PopupMenu();
// Add a command to edit the current Group
contextMenu.Commands.Add(new UICommand("Edit this Group", (contextMenuCmd) =>
{
Frame.Navigate(typeof(LocationGroupCreator), groupName);
}));
// Add a command to delete the current Group
contextMenu.Commands.Add(new UICommand("Delete this Group", (contextMenuCmd) =>
{
SQLiteUtils slu = new SQLiteUtils(); …Run Code Online (Sandbox Code Playgroud) 想想这个,
Task task = new Task (async () =>{
await TaskEx.Delay(1000);
});
task.Start();
task.Wait();
Run Code Online (Sandbox Code Playgroud)
调用task.Wait()不等待任务完成,下一行立即执行,但如果我将async lambda表达式包装到方法调用中,代码将按预期工作.
private static async Task AwaitableMethod()
{
await TaskEx.Delay(1000);
}
Run Code Online (Sandbox Code Playgroud)
然后(根据svick的评论更新)
await AwaitableMethod();
Run Code Online (Sandbox Code Playgroud)