1,105,423 Community Members

looping HttpWebRequest hangs the program until it is finished

Member Avatar
Newbie Poster
9 posts since Jul 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]

My code is working but my only problem is that the entire program freezes while it is looping and the freeze only stops when the loop is done, is there any way to get rid of this freezing? i want to see it display from 1 to 21 but instead it freezes and only displays number 21 right away.

Here is my code. Should i change something so that it would tweak its performance? Thanks in advance

 Dim x As Integer = 0
        Dim POST As String = "authenticity_token=weZnH8V68yQSnQh91UtDZyatys%2FXtPQGN2vooyW4opY%3D&email%5Bto_address%5D=intes2010%40gmail.com&email%5Bfrom_name%5D=Test&email%5Bfrom_address%5D=test%40email.com&email%5Bnote%5D=today+is+a+big+success&email%5Bcopy_yourself%5D=0&id=house-of-pies-466226000"
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse
        Dim tempCookies As New CookieContainer
        request = CType(WebRequest.Create("http://www.yellowpages.com/los-angeles-ca/mip/house-of-pies-466226000/send_email?lid=1000083727260"), HttpWebRequest)
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = POST.Length
        request.Method = "POST"
        request.KeepAlive = True
        request.CookieContainer = tempCookies

        Dim requestStream As Stream = request.GetRequestStream()
        Dim postBytes As Byte() = Encoding.ASCII.GetBytes(POST)
        requestStream.Write(postBytes, 0, postBytes.Length)

        response = CType(request.GetResponse(), HttpWebResponse)
        Dim postreader As New StreamReader(response.GetResponseStream())

        Dim thepage As String = postreader.ReadToEnd
        RichTextBox1.Text = thepage

        x = x + 1
        Label1.Text = x
    Loop While (x <= 20)
Member Avatar
Junior Poster in Training
50 posts since Aug 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]

Search for "HttpWebRequest asyncronously" or Click Here

Member Avatar
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
put your code inside of threading
imports System.Threading

private sub sample


end sub

then call your thread by putting this code inside of the button
dim Sam as new System.Threading.Thread(Addressof sample): Sam.start

in form load add this
  CheckForIllegalCrossThreadCalls = False

  its not the best way of using threading but it might work :)
This article has been dead for over three months: Start a new discussion instead
Start New Discussion
Tags Related to this Article