title: Download file using HttpClient with ProgressBar
body: <p>Hello I'm just learning how to download file using httpclient.
  Can anybody help me update my progressbar?
  The download is working but not the progressbar.</p>
  <p>My code for progressbar isnt't working it's not updating</p>
  <pre><code>async Task&lt;string&gt; GetWebSource(string url, string outputpath)
      {
          int count = 0;
          ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
          ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CertificateValidationCallback);
          string result = string.Empty;
          try
          {
              HttpWebRequest request = await Task.Run(() =&gt; (HttpWebRequest)WebRequest.Create(url));
              request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
              request.Proxy = null;
              request.Method = &quot;GET&quot;;
              request.UserAgent = &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36&quot;;
       
              string output = Path.Combine(outputpath, GetFilenameFromUrl(url));
  
              using (var httpWebResponse = await Task.Run(() =&gt; request.GetResponseAsync()))
              {
                  using (var file = new FileStream(output, FileMode.Create, FileAccess.Write))
                  {
                      await Task.Run(() =&gt; httpWebResponse.GetResponseStream().CopyTo(file));
  
                      count++;
                      progressBar1.Value = (int)(count / (double)httpWebResponse.ContentLength * 100);
                  }
              }
  
              if (request != null)
              {
                  request.Abort();
              }
          }
          catch (Exception)
          {
          }
          return result;
      }
  </code></pre>