Results 1 to 29 of 29

Thread: Adding a For statement into a Backgroundworker

Hybrid View

  1. #1
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Adding a For statement into a Backgroundworker

    I've already given you the link. Have you read post #2 of my CodeBank thread on Using The BackgroundWorker or not?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Apr 2011
    Posts
    19

    Re: Adding a For statement into a Backgroundworker

    Quote Originally Posted by jmcilhinney View Post
    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)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width