I have hit a road bump. I have been piecing together bits of code that I have found and customized it to work with my app. Now the following code works find out of a separate thread, but as soon as I put it into its on threads it doesn't want to connect.
Any suggestions?
Code:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click getAlexaNow = New Thread(AddressOf ThreadTask) getAlexaNow.IsBackground = True getAlexaNow.Start() End Sub Private Sub ThreadTask() Dim intList As Integer Dim strAlexa As String intList = "0" strSearch = txtSearch.Text Do Until intList = linksList.Items.Count Dim linkUrl As String = "http://www.alexa.com/search?q=" & linksList.Items.Item(intList) Try Dim myResponse As Net.HttpWebResponse = Net.HttpWebRequest.Create(linkUrl).GetResponse '// connect. Dim myStream As IO.Stream = myResponse.GetResponseStream() '// get. Dim myReader As New IO.StreamReader(myStream) '// read. Dim myWebFileInfo As String = myReader.ReadToEnd '// get innerHtml of Page. myReader.Close() : myStream.Close() : myResponse.Close() '// close reader, information stream, and connection. RichTextBox3.Text = myWebFileInfo If InStr(myWebFileInfo, "No regional data") Then alexaList.Items.Add((linksList.Items.Item(intList)) & ":" & "No Alexa rank") Exit Try End If '// get location of <pre> by index. Dim myStartIndex As Integer = myWebFileInfo.IndexOf(">US</a>:") + 8 '// add +5 to not add "<pre>" to final result. '// get location of </pre> by index. Dim myEndIndex As Integer = myWebFileInfo.IndexOf(" </li>") '// subtract to get a total number for the substring length result. Dim myStringLengthToExtract As Integer = myEndIndex - myStartIndex '// display result. strAlexa = myWebFileInfo.Substring(myStartIndex, myStringLengthToExtract) If InStr(strAlexa, "XHTML") Then alexaList.Items.Add((linksList.Items.Item(intList)) & ":" & "No Alexa rank") Else If InStr(strAlexa, "%%") Then Else alexaList.Items.Add((linksList.Items.Item(intList)) & ":" & strAlexa) End If End If Catch ex As Exception MsgBox("Connection Error.", MsgBoxStyle.Critical, "myCool Error Message") End Try intList = intList + 1 Loop End Sub




Reply With Quote