[英]I can't await awaitable?
Visual Studio complains on the following: 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>'
I thought I've done this before, GetStringAsync is not awaitable? 我以为我之前已经这样做了,GetStringAsync是不是值得期待?
You're probably targeting .NET 4.0. 您可能正在瞄准.NET 4.0。
If you can, switch to .NET 4.5 which supports async/await semantics. 如果可以,请切换到支持async / await语义的.NET 4.5。
If you can't, consider using the Async Targeting Pack:
https://www.nuget.org/packages/Microsoft.CompilerServices.AsyncTargetingPack
如果不能,请考虑使用Async Targeting Pack:
https :
//www.nuget.org/packages/Microsoft.CompilerServices.AsyncTargetingPack
Edit 编辑
As per the comments, Microsoft.Bcl.Async
should be used instead: https://www.nuget.org/packages/Microsoft.Bcl.Async 根据评论,应使用
Microsoft.Bcl.Async
代替: https : //www.nuget.org/packages/Microsoft.Bcl.Async
Ensure that client.GetStringAsync("url") is an async Task 确保client.GetStringAsync(“url”)是异步任务
private async Task GetStringAsync(string str)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.