Reputation: 1113
Well, I created a downloader that checks all files in a list and then it downloads all files.
Example:
Node Class:
public class Node
{
public string fileName { get; set; }
public string fileHash { get; set; }
public int fileSize { get; set; }
public Node(string fName, string fHash, int fSize)
{
fileName = fName;
fileHash = fHash;
fileSize = fSize;
}
}
public class Nodes : List<Node>
{
public void Fill(string name, string hash, int size)
{
Add(new Node(name, hash, size));
}
}
itemsUpdate:
List<Node> itemsUpdate = new List<Node>();
Downloading the files:
FileDownload fDownload;
foreach (Node n in itemsUpdate)
{
//fDownload contains all for the async download.
fDownload.Download(url, n.fileName);
//Here I show the current progress
while (fDownload.Progress != 100)
{
lblProgress.Text = fDownload.Progress.ToString() + "%";
}
lblProgress.Text = "100%";
}
What I want to know is how to calculate the total progress of the download. Hope someone could help me. Thanks
Upvotes: 0
Views: 154
Reputation: 178
first calculate sum of all file size, then calculate total progress each time
long sum = 0;
foreach(Node n in itemsUpdate)
{
sum += n.fileSize;
}
long nodeSum = 0;
foreach (Node n in itemsUpdate)
{
//fDownload contains all for the async download.
fDownload.Download(url, n.fileName);
//Here I show the current progress
while (fDownload.Progress != 100)
{
lblProgress.Text = ((nodeSum + fDownload.Progress * n.fileSize)/sum).ToString() + "%";
}
nodeSum += n.fileSize;
}
Upvotes: 1
Reputation: 1202
callbacks
progress must be checked not only relatively to current file size, but relatively to all files sizes sumUpvotes: 0