Visual Studio抱怨如下:
public RelayCommand SendRegistrationCommand { get; private set; }
public async void SendRegistration()
{
HttpClient client = new HttpClient();
var response = await client.GetStringAsync("url");
// ... todo
}
Cannot await 'System.Threading.Tasks.Task<string>'
我以为我之前已经这样做了,GetStringAsync不值得等待吗?
答案 0 :(得分:20)
您可能正在瞄准.NET 4.0。
如果可以,请切换到支持async / await语义的.NET 4.5。
如果你不能,请考虑使用Async Targeting Pack:https://www.nuget.org/packages/Microsoft.CompilerServices.AsyncTargetingPack
修改强>
根据评论,应使用Microsoft.Bcl.Async
代替:https://www.nuget.org/packages/Microsoft.Bcl.Async
答案 1 :(得分:-3)
确保client.GetStringAsync(“url”)是异步任务
private async Task GetStringAsync(string str)
{
}