DEV Community


Discussion on: Download file using HttpClient wrapper asynchronously.

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.

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.