[英]async method lacks await operators message when I call another async method from it?
我的OnAppearing消息是異步的,我從中調用另一個異步方法,它有一些修改UI的代碼。 然后我做了一些工作,最后再次修改UI。
這是代碼。 但是我收到一條令我困惑的警告信息。 我在下面添加了警告代碼。
protected async override void OnAppearing()
{
base.OnAppearing();
// actions
CreateListSectionAsync();
}
public async void CreateListSectionAsync()
{
// modify UI
// do some work that takes time
await Task.Run(() =>
{
Device.BeginInvokeOnMainThread(() =>
{
// modify UI
});
});
}
ListPage.xaml.cs(39,39):警告CS1998:此異步方法缺少'await'運算符並將同步運行。 考慮使用'await'運算符等待非阻塞API調用,或'await Task.Run(...)'在后台線程上執行CPU綁定工作。 (CS1998)
為什么我會收到此警告,如何解決?
await CreateListSectionAsync();
更改功能的簽名以返回Task not void
public async Task CreateListSectionAsync()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.