반응형
람다 식을 비동기로 어디에 표시합니까?
이 코드가 있습니다 :
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에서의 검사와 불평 있음 " 이 호출 대망 없기 때문에 호출이 완료되기 전에, 현재의 방법의 실행이 계속된다. 호출 결과에 'AWAIT"연산자를 적용하는 와 라인 ( " 논평).
그래서 나는 "await"를 앞에 붙 였지만, 물론 어딘가에 "async"를 추가해야합니다.
람다를 비동기로 표시하려면 async
인수 목록 앞에 추가하면 됩니다.
// 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);
}));
그리고 익명의 표현을 사용하는 사람들에게는 :
await Task.Run(async () =>
{
SQLLiteUtils slu = new SQLiteUtils();
await slu.DeleteGroupAsync(groupname);
});
참고 URL : https://stackoverflow.com/questions/14015319/where-do-i-mark-a-lambda-expression-async
반응형
'Programing' 카테고리의 다른 글
'for (;;);와 같은 Ajax 호출 응답은 무엇입니까? (0) | 2020.05.11 |
---|---|
왜 파이썬 코드가 길이 메소드 대신 len () 함수를 사용합니까? (0) | 2020.05.11 |
ORA-12514 TNS : listener가 현재 접속 설명자에서 요청한 서비스를 모릅니다 (0) | 2020.05.10 |
git stash blunder : git stash pop은 병합 충돌로 끝났습니다. (0) | 2020.05.10 |
jQuery에서 live ()를 on ()으로 바꾸기 (0) | 2020.05.10 |