Add Progress reporting to capabilities to HttpClient
using HttpClientProgress;
A little routine to download a PDF file from the internet.
async Task DownloadFile ()
{
// for the sake of the example lets add a client definition here
var client = new HttpClient ();
var docUrl = "https://pspdfkit.com/downloads/case-study-box.pdf";
var filePath = Path.Combine (Path.GetTempPath (), "case-study-box.pdf");
// Setup your progress reporter
var progress = new Progress<float> ();
progress.ProgressChanged += Progress_ProgressChanged;
// Use the provided extension method
using (var file = new FileStream (filePath, FileMode.Create, FileAccess.Write, FileShare.None))
await client.DownloadDataAsync (docUrl, file, progress);
}
void Progress_ProgressChanged (object sender, float progress)
{
// Do something with your progress
Console.WriteLine (progress);
}
why is the code has an error syntax on the part of :
float GetProgressPercentage (float totalBytes, float currentBytes) => (totalBytes / currentBytes) * 100f;