所以本质上我有一个下载文件的表格,称为file.jpg,例如每隔一小时左右旋转一次,我有一个按钮可以开始下载,它会随机下载任意时间(主要是自学练习)我喜欢在progressChange中添加代码,我想以某种方式获取随着时间的推移接收到的字节以获得kb/s。我用谷歌搜索,找不到任何东西。我不需要任何花哨的网络堆栈,因为它们是标准的 jpeg,所以它不是太大(事实上,当文件下载时,当我清除进度条时,我从来没有看到它开始......但我离题了)我喜欢看到平均 kb/s,即使我看到它 2 秒(每个文件大约 1 meg)。任何帮助深表感谢。
private void btnStart_Click(object sender, EventArgs e)
{
btnStart.Enabled = false;
btnStop.Enabled = true;
WebClient webclient = new WebClient();
webclient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webclient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
// you need to increment the number !!!
// add the file to the list.
// single click should preview
// progress bar should clear after it downloads
// the status bar as well should be done
int num = nextIndex() + 1;
string file = @"C:\IMG\IMG_";
file += string.Format("{0:d5}", num);
file += ".jpg";
webclient.DownloadFileAsync(new Uri("http://www.foobar.com/file.jpg"), file);
lstFiles.Enabled = false;
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
// display kb/sec as well??
pbDownload.Value = e.ProgressPercentage;
}