โค้ดในการโหลด ครับ
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้private long BytesReceived = 0;
private long TotalBytesToReceive = 0;
LinkPictures.ForEach(_link =>
{
string link = _link;
string FileLoad = fol + "\\" + i.ToString("000") + ".jpg";//System.IO.Path.GetFileName(link); //
if (!System.IO.File.Exists(FileLoad))
{
this.TotalBytesToReceive += GetFileSizeFormUrl(new Uri(link)).Result;
using (WebClient wc = new WebClient())
{
wc.DownloadFileCompleted += (s, e) =>
{
completeUrl++;
_DownloadFileCompleted(Url, completeUrl, LinkPictures.Count, fol);
Thread.Sleep(2000);
};
wc.DownloadProgressChanged += (s, e) =>
{
this.BytesReceived += e.BytesReceived;
};
wc.DownloadFileAsync(new Uri(link), FileLoad);
OnDownloaderProgressChanged(new DownloaderProgressChangedEventArgs("load link:" + link, "Status", 0, this.TotalBytesToReceive));
Thread.Sleep(2000);
}
i++;
}
else
{
OnDownloaderProgressChanged(new DownloaderProgressChangedEventArgs("Exits File:" + FileLoad, "Status", this.BytesReceived, this.TotalBytesToReceive));
Thread.Sleep(1000);
completeUrl++;
_DownloadFileCompleted(Url, completeUrl, LinkPictures.Count, fol);
i++;
}
});
อย่างเช่นเราโหลด ทีละ 10 ไฟล์
เราจะดึง BytesReceived ทั้ง 10 ไฟล์ มา รวมทังหมด ได้ยังไง ครับ
ปกติ ถ้าใช้ DownloadProgressChanged ก็จะได้แค่ ทีละไฟล์ เอง
C# WebClient อยากเช็ค BytesReceived และ TotalBytesToReceive ในกรณีที่มี การโหลดหลายๆ ไฟล์ ครับพร้อมกัน ครับ
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้
อย่างเช่นเราโหลด ทีละ 10 ไฟล์
เราจะดึง BytesReceived ทั้ง 10 ไฟล์ มา รวมทังหมด ได้ยังไง ครับ
ปกติ ถ้าใช้ DownloadProgressChanged ก็จะได้แค่ ทีละไฟล์ เอง