我必须在HttpClient中使用ContinueWith吗?

时间:2013-04-16 21:16:40

标签: asp.net-web-api dotnet-httpclient

使用System.Net.Http.HttpClient调用rest服务时,我的代码如

var response = client.GetAsync("api/MyController").Result;
if(response.IsSuccessStatusCode)
...

是正确的还是我应该做的

client.GetAsync("api/MyController").ContinueWith(task => { var response = task.Result; ...}

1 个答案:

答案 0 :(得分:0)

做第二个更安全。在各种情况下,第一个选项可能导致死锁。