
Originally Posted by
jmcilhinney
I've already given you the link. Have you read post #2 of my CodeBank thread on Using The BackgroundWorker or not?
No actually, I had not read it, but now I have an I've made a little more progress.
Code:
Private Sub btnLeech_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Leech_btn.Click
Worker.RunWorkerAsync((CInt(Me.Website_list.Items.Count)))
End Sub
'Open a bunch of new threads to download sources of webpages
Private Sub Fetch(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Worker.DoWork
Dim websiteUri As Uri = Nothing
Dim Website As String
Dim Count As Integer
For I As Integer = 0 To Count
If TypeOf e.Argument Is Integer Then
Count = CInt(e.Argument)
End If
Using wc As Net.WebClient = New Net.WebClient
AddHandler wc.DownloadStringCompleted, AddressOf SourceDownloaded
If Uri.TryCreate(Website, UriKind.Absolute, websiteUri) Then
wc.DownloadStringAsync(New Uri(Website))
Worker.ReportProgress(I, I & " iterations complete")
Threading.Thread.Sleep(250)
Else
If Notify.Checked = True Then
TrayIcon.ShowBalloonTip(1, "Invalid website", "There was a invalid site in the list." & Website.ToString, ToolTipIcon.Error)
Me.TrashSite_list.Items.Add(Website)
Else
Me.TrashSite_list.Items.Add(Website)
End If
End If
End Using
Next
End Sub
But how do I do this in Backgroundworker:
Code:
Website = Me.Website_list.Items.Item(I)