【问题标题】:Do I have to use ContinueWith with HttpClient?我必须将 ContinueWith 与 HttpClient 一起使用吗?
【发布时间】:2013-04-16 21:16:40
【问题描述】:

当使用 System.Net.Http.HttpClient 调用休息服务时,我有类似的代码

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

这是正确的还是我应该这样做

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      • 1970-01-01
      • 2014-05-11
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      相关资源
      最近更新 更多