1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Multithreading with webClient & HttpWebRequest

Discussion in 'Visual Basic .NET' started by russellhope, Sep 11, 2015.

  1. russellhope

    russellhope Registered Member

    Joined:
    Jan 11, 2010
    Messages:
    81
    Likes Received:
    6
    Hey,

    This has been a bit of a pain trying to work this out.

    Basically I have a bot that will sign up to a site, does what it needs to do and then repeats.

    Instead of having to have 20 bots open on my computer I want to multi thread it.

    Now I've tried likes of this, passing a random number to my site, echo'ing it on the site and returning it to a listbox, but it doesn't go any faster with 100 threads than 1 thread?

    Code:
    For i = 0 To 10            Dim thread = New System.Threading.Thread(AddressOf httpfetch)
                thread.IsBackground = True
                thread.Start()
            Next
    Code:
    Public Sub httpfetch()
    
    
    
            Dim rndnumber As Random
            Dim number As Integer
            rndnumber = New Random
            number = rndnumber.Next(1, 4)
    
    
            Dim webClient As New System.Net.WebClient
            Dim result As String = webClient.DownloadString("http://website.com/fetcher.php?i=" & number)
    
    
            ListBox1.Items.Add(result)
    
    
            TextBox2.Text = TextBox2.Text + 1
    
    
            httpfetch()
    
    
        End Sub
    any help please?

    Thanks
     
  2. Psychop1

    Psychop1 Registered Member

    Joined:
    Jul 30, 2010
    Messages:
    63
    Likes Received:
    19
    You need to marshal your crossthread calls.
     
  3. Psychop1

    Psychop1 Registered Member

    Joined:
    Jul 30, 2010
    Messages:
    63
    Likes Received:
    19
    Research information about delegates and marshaling on vb.net