Hi @Jassim Al Rahma , you could try the following code to get what you wanted.
HttpClient client = new HttpClient();
using (var stream = await client.GetStreamAsync(url))
{
using (MemoryStream ms = new MemoryStream())
{
byte[] buffer = new byte[1024];
Console.WriteLine("DownloadStarted");
totalBytes = client.MaxResponseContentBufferSize;
for (; ; )
{
int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
await Task.Yield();
break;
}
receivedBytes += bytesRead;
int received = unchecked((int)receivedBytes);
int total = unchecked((int)totalBytes);
double percentage = ((float)received) / total;
Console.WriteLine(received / (1024) + "Kb / " + total / (1024 )+" Kb");
Console.WriteLine("Completed : " + percentage + "%");
}
}
}
Or you could refer to How to get accurate download/upload speed in C#.NET?.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.