正如这里提到的(伟大的博客,顺便说一句),为了正确工作 CPU 绑定调用,需要适当的异步调用。例如,不
await Task.Run(() => Thread.Sleep(100));
但
await Task.Delay(100);
Json.net 反序列化是否有类似物?
await TaskEx.Run(() => JsonConvert.DeserializeObject<PocoProduct>(resultString));
使用环境:
async public Task<ProductsAnswer> RequestServerAsync()
{
// Just a wrapper for await httpWebRequest.GetResponseAsync() and await postStreamReader.ReadToEndAsync()
var resultString = await new NetworkManager().GetAsync(Constants.SERVER_REQUEST);
// await TaskEx.Run(() => JsonConvert.DeserializeObject<PocoProduct>(resultString));
var answer = await ParseProductsFromString(resultString);
return answer;
}