Will static HttpClient in webapi triggers any issue?

Viewed 446

I just realized that we should reuse HttpClient other than dispose them again and again. However, as my app is on asp.net, if I don't do this:

using (var client = new HttpClient())
{
     client.SendAsync(someurl, something);
}

Instead, put client in my controller as a static variable for example:

public class MyController{
            public static HttpClient MyClient;
       public class MyController()
       {
            ////some configuration for the HttpClient
       }
       public async Task<Model> get()
       {
               await MyClient.PostAsJsonAsync(url, someModel);
               return something
       }
}

When multi-users call my api, will it trigger thread related issues?

This msdn article does say PostAsync is thread safe. https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx#Anchor_5

Will it apply to my usage scenario? Also if there are hundred of concurrent requests, will single HttpClient cope with that?

0 Answers
Related