private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e, Stopwatch sw)
{
string downloadProgress = e.ProgressPercentage + "%";
string downloadSpeed = string.Format("{0} MB/s", (e.BytesReceived / 1024.0 / 1024.0 / sw.Elapsed.TotalSeconds).ToString("0.00"));
string downloadedMBs = Math.Round(e.BytesReceived / 1024.0 / 1024.0) + " MB";
string totalMBs = Math.Round(e.TotalBytesToReceive / 1024.0 / 1024.0) + " MB";
string progress = $"{downloadedMBs}/{totalMBs} ({downloadProgress}) @ {downloadSpeed}"; // 10 MB / 100 MB (10%) @ 1.23 MB/s
lblDownloadProgress.Text = progress;
textProgressBar1.Value = e.ProgressPercentage;
textProgressBar1.CustomText = progress;
}
I can see with a break point that the variable value of e.BytesReceived
and e.TotalBytesToReceive
are changing but on the progress variable the downloadedMBs
and totalMBs
values are 0 all the time.
Edit:
Example for values that cause the problem:
e.BytesReceived
: 2196
e.TotalBytesToReceive
: 194899