title: Httpclient This instance has already started one or more requests. Properties can only be modified before sending the first request
body: <p>I am creating an application in .Net Core 2.1 and I am using http client for web requests. The issue is I have to send parallel calls to save time and for that I am using Task.WhenAll() method but when I hit this method I get the error "This instance has already started one or more requests. Properties can only be modified before sending the first request" Previously I was using RestSharp and everything was fine but I want to use httpclient. Here is the code:</p>
  
  <pre><code>public async Task&lt;User&gt; AddUser(string email)
  {
      var url = "user/";
      _client.BaseAddress = new Uri("https://myWeb.com/");
      _client.DefaultRequestHeaders.Accept.Clear();
      _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(Constants."application/json"));
      _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
      var json = new {email = email }
      var response = await _client.PostAsJsonAsync(url,json);
      if (response .IsSuccessStatusCode)
      { ....
  </code></pre>
  
  <p>Here is the constructor:</p>
  
  <pre><code>private readonly HttpClient _httpClient;
  
  public UserRepository(HttpClient httpClient)
  {         
      _httpClient = httpClient;
  }
  </code></pre>
  
  <p>Method calling:</p>
  
  <pre><code>var user1 = AddUser("user@user.com");
  var user2 = AddUser("test@test.com");
  
  await Task.WhenAll(user1, user2);
  </code></pre>
  
  <p>and here is the startup configuation:</p>
  
  <pre><code>services.AddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();
  </code></pre>
  
  <p>So what am I doing wrong? Do I need to change AddSingleton with AddTransient() or is there any other issue. One more question do I need to use _client.Dispose() after the response because the tutorial which I followed didn't use dispose method so I am little confused in that.</p>