我这里有一些代码,想知道在哪里放置等待。我已经尝试过 lamba => 和常规方法,但都没有成功。
private async void ContextMenuAbroad(object sender, RightTappedRoutedEventArgs args)
{
CheckBox ckbx = null;
if (sender is CheckBox)
{
ckbx = sender as CheckBox;
}
if (null == ckbx)
{
return;
}
string nameOfGroup = ckbx.Content.ToString();
var contextMenu = new PopupMenu();
contextMenu.Commands.Add(new UICommand("Edit this Group", (contextMenuCmd) =>
{
Frame.Navigate(typeof(LocationGroupCreator), nameOfGroup );
}));
contextMenu.Commands.Add(new UICommand("Delete this Group", (contextMenuCmd) =>
{
SQLiteUtils rfd = new SQLiteUtils();
rfd.DeleteGroupAsync(nameOfGroup );
}));
await contextMenu.ShowAsync(args.GetPosition(this));
}
我添加了一个等待,但是我需要在某处添加一个异步......但是在哪里?
Resharpers 检查提示:“因为没有等待这个调用,当前方法的执行在调用完成之前继续。考虑将 'await' 运算符应用于调用的结果”
非常感谢任何帮助!
最佳答案
简单地在参数列表之前添加async
// Command to delete the current Group
contextMenu.Commands.Add(new UICommand("Delete this Group", async (contextMenuCmd) =>
{
SQLiteUtils rfd = new SQLiteUtils();
await rfd.DeleteGroupAsync(groupName);
}));
关于c# - 如何标记异步 lambda 表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52384065/