DEV Community

loading...

Discussion on: Download file using HttpClient wrapper asynchronously.

Collapse
alexjitbit profile image
Alex Yumashev

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.

docs.microsoft.com/en-us/dotnet/ap...

Collapse
1001binary profile image
1001binary Author

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.