|
-
Nov 27th, 2012, 07:06 AM
#32
Re: Using the BackgroundWorker Component
 Originally Posted by Tompkins
Code:
BackgroundWorker1_DoWork
Dim worker As System.ComponentModel.BackgroundWorker = DirectCast(sender, System.ComponentModel.BackgroundWorker)
Dim lines As String() = FileToArray(My.Computer.FileSystem.CurrentDirectory & "/filelist.txt")
Dim line As String
For Each line In lines
uriSource = New Uri("http://localhost/" & line)
uriPath = My.Computer.FileSystem.CurrentDirectory & line
???For i As Integer = 1 To 100
worker.ReportProgress(i, "Downloading : " & line)
??????Next i
downloading.DownloadFile(uriSource, uriPath)
Next line
----------------
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Me.ProgressBar1.Value = e.ProgressPercentage
Me.Label6.Text = TryCast(e.UserState, String)
End Sub
i Would like to know how to make progress bar work with my "for each" line reader for downloading. for example how should i get BytesReceived .
or like
Code:
ProgressBar1.Maximum = e.TotalBytesToReceive
ProgressBar1.Value = e.BytesReceived
thanks in advance!!
There are various options but the simplest is to just look at the name of the first parameter of the ReportProgress method: percentProgress. Instead of setting the Maximum of the ProgressBar to the total number of bytes and the Value to the actual number of bytes, simply leave the Maximum as the default 100 and calculate the percentage yourself and pass that one value, e.g. if you have 5,000,000 bytes to download and you've downloaded 2,000,000 then the percentage is 40% so that's what you pass to ReportProgress.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|