title: Download file with WebClient or HttpClient?
body: <p>I am trying to download file from a URL and I have to choose between WebClient and HttpClient. I have referenced <a href="https://stackoverflow.com/questions/20530152/deciding-between-httpclient-and-webclient">this</a> article and several other articles on the internet. Everywhere, it is suggested to go for HttpClient due to its great async support and other .Net 4.5 privileges. But I am still not totally convinced and need more inputs. </p>
  
  <p>I am using below code to download file from internet:</p>
  
  <p><strong>WebClient:</strong></p>
  
  <pre><code>WebClient client = new WebClient();
  client.DownloadFile(downloadUrl, filePath);
  </code></pre>
  
  <p><strong>HttpClient:</strong></p>
  
  <pre><code>using (HttpClient client = new HttpClient())
  {        
      using (HttpResponseMessage response = await client.GetAsync(url))
      using (Stream streamToReadFrom = await response.Content.ReadAsStreamAsync())
      {
      }
  }
  </code></pre>
  
  <p>From my perspective, I can see only one disadvantage in using WebClient, that would be the non async call, blocking the calling thread. But what if I am not worried about the blocking of thread or use <code>client.DownloadFileAsync()</code> to leverage the async support? </p>
  
  <p>On the other hand, if I use HttpClient, ain't I loading every single byte of a file into memory and then writing it to a local file? If the file size is too large, won't memory overhead be expensive? Which could be avoided if we use WebClient, since it will directly write to local file and not consume system memory.</p>
  
  <p>So, if performance is my utter priority, which approach should I use for download? I would like to be clarified if my above assumption is wrong, and I am open to alternate approach as well.</p>