2

At the moment I have a queue system that places all of the links to download files from and it downloads them one by one.

What I have been trying to do is have not 1 but 2 progress bars. The top progress bar will be for the progress of the current file and the one below will be for the overall progress, before all the files finish downloaded.

I have tried to come up with ways to have this but I can't figure out how I would go about doing it.

What I have tried is this:

If Me.fileUrls.Count = 1 Then
    CProgressBarTotal.Value = Help.ProgPercent.Text
Else
    CProgressBarTotal.Value = Help.ProgPercent.Text / Me.fileUrls.Count
End If

And I realised after, that this wouldn't work. I also tried to think of other ways to do it but, I couldn't think of anything.

Does anyone know how I would be able to go about doing this? Thanks.

avgcoder
  • 372
  • 1
  • 9
  • 27
  • What's the goal of the "total progress" bar? To show the progress as a percentage of files downloaded (in which case, your algorithm is close), or to show the percentage of total bytes downloaded (in which case, you need to sum the size of all files, keep track of all bytes downloaded and use the totals as your ratio). – PaulProgrammer Sep 09 '13 at 16:39
  • Either way would do it but it sounds like the percentage of total bytes downloaded would be better. What do you suggest? I was originally planning to show the percentage of files downloaded, but I like the percentage of total bytes downloaded more. – avgcoder Sep 09 '13 at 16:54
  • if you want them to progress at the same time shouldn't you now be looking at Multithreading? – Manny265 Sep 10 '13 at 13:57

2 Answers2

0

To have a second progress bar that tracks total bytes downloaded:

  1. Prior to showing the download screen, determine the total number of bytes to be downloaded. The specifics here depend on the download mechanism, but most FTP and HTTP servers will provide file sizes. In cases where they don't you'll have to make a reasonable estimate. Store this in an accessible member variable.

  2. Create an accessible member variable for the total number of bytes downloaded. Bind this to the same routine that updates your single-file progress, so that each download "tick" also accumulates the "number of bytes downloaded" field in addition to the percentage of the current file as it does now.

  3. Bind the total number of bytes to the "total percentage" progress bar maximum value. Bind the bytes downloaded counter to the position of the progress bar.

For extra points: Configure the bindings in a dynamic way, such that if a file is added to (or removed from) your download queue, the total number of bytes to download count is updated in real-time and the progress bar resets progress accordingly.

PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56
0

You shouldn't need an if statement:

CProgressBarTotal.Value = (currentFileNumber / Me.fileUrls.Count + Help.ProgPercent.Text / 100 / Me.fileUrls.Count) * CProgressBarTotal.Maximum
xpda
  • 15,585
  • 8
  • 51
  • 82