Where do I mark a lambda expression async?

后端 未结 2 996
情深已故
情深已故 2020-12-04 14:51

I\'ve got this code:

private async void ContextMenuForGroupRightTapped(object sender, RightTappedRoutedEventArgs args)
{
    CheckBox ckbx = null;
    if (se         


        
相关标签:
2条回答
  • 2020-12-04 15:19

    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);
    }));
    
    0 讨论(0)
  • 2020-12-04 15:20

    And for those of you using an anonymous expression:

    await Task.Run(async () =>
    {
       SQLLiteUtils slu = new SQLiteUtils();
       await slu.DeleteGroupAsync(groupname);
    });
    
    0 讨论(0)
提交回复
热议问题