You should NEVER NEVER EVER put HttpClient inside using, you should reuse an existing var and keep it alive thought the lifetime of your app.
HttpClient is intended to be instantiated once and re-used throughout the life of an application. Instantiating an HttpClient class for every request will exhaust the number of sockets available under heavy loads.
You should NEVER NEVER EVER put HttpClient inside
using
, you should reuse an existing var and keep it alive thought the lifetime of your app.docs.microsoft.com/en-us/dotnet/ap...
Thanks Alex :). You're right.
The DownloadFile function is just a sample function to demonstrate how to download file using HttpClient asynchronously.
In practice, the existing HttpClient var should be reused throughout the lifetime of the application.
I just updated this post.