我在哪里标志着一个lambda前pression异步? [英] Where do I mark a lambda expression async?
本文介绍了我在哪里标志着一个lambda前pression异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我这有code:
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();
slu.DeleteGroupAsync(groupName); // this line raises Resharper's hackles, but appending await raises err msg. Where should the "async" be?
}));
// Show the context menu at the position the image was right-clicked
await contextMenu.ShowAsync(args.GetPosition(this));
}
...这ReSharper的视察抱怨着,在完成调用之前的因为这个呼叫没有等待,目前的方法继续执行。考虑应用'等待'操作的调用的结果(与注释的行)。
所以,我prepended一个等待来了,但是,当然,我则需要添加异步的地方,太 - ?哪来
And so, I prepended an "await" to it but, of course, I then need to add an "async" somewhere, too - but where?
推荐答案
要纪念一个lambda异步,只需prePEND 异步
参数列表前:
To mark a lambda async, simply prepend async
before its argument list:
// Add a command to delete the current Group
contextMenu.Commands.Add(new UICommand("Delete this Group", async (contextMenuCmd) =>
{
SQLiteUtils slu = new SQLiteUtils();
await slu.DeleteGroupAsync(groupName);
}));
这篇关于我在哪里标志着一个lambda前pression异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文