2012-12-23 17 views
146

Bu kodu var:Bir lambda ifadesini nerede işaretliyim?

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'ın muayene bu çağrı beklenen olmadığı için çağrı tamamlanmadan önce, şimdiki yöntemin yürütülmesine devam "ile ilgili şikayet olduğunu uygulayabilirsiniz. aramasının sonucuna '' bekle '' (yorum ile birlikte).

Ve buna bir "bekle" hazırladım, ama tabiki, o zaman bir yerde "async" eklemem gerekiyor - ama nerede?

cevap

236

bir lambda asenk işaretlemek için, onun bağımsız değişken listesinin önce async prepend:

// 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

Yani basit ... henüz belirgin hiç! +1 – ppumkin

İlgili konular