Hi ShalvaGabriel-1621,
The whole process of the stopwatch is:
- reset
- start
- stop
You did not stop and reset the stopwatch
after the first download.
After modification:
private async Task DownloadAsync() {
using (var client = new WebClient()) {
client.DownloadFileCompleted += (s, e) => lblStatus.Text = "Download File Completed.";
client.DownloadProgressChanged += (s, e) => progressBar1.Value = e.ProgressPercentage;
client.DownloadProgressChanged += (s, e) => lblAmount.Text = FormatBytes(e.BytesReceived);
client.DownloadProgressChanged += (s, e) => lblSpeed.Text = string.Format("{0} kb/s", (e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds).ToString("0.00"));
client.DownloadProgressChanged += (s, e) => lblDownloadSize.Text = Convert.ToInt64(client.ResponseHeaders["Content-Length"]).ToString();
client.DownloadProgressChanged += (s, e) =>
{
lblDownloadProgress.Text = "%" + e.ProgressPercentage.ToString();
lblDownloadProgress.Left = Math.Min(
(int)(progressBar1.Left + e.ProgressPercentage / 100f * progressBar1.Width),
progressBar1.Width - lblDownloadProgress.Width
);
};
for (int i = 0; i < urls.Count; i++) {
sw.Reset();
sw.Start();
await client.DownloadFileTaskAsync(new Uri(urls[i]), @"d:\satImages\img" + i + ".gif");
client.DownloadFileCompleted += (s, e) => sw.Stop();
}
}
}
private async void BtnStart_Click(object sender, EventArgs e) {
lblStatus.Text = "Downloading...";
await DownloadAsync();
}
Output:
Best regards,
Jiale Xue
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.