Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27055

VS 2010 [RESOLVED] Using webProxy Slow

$
0
0
Hey Guys,

What i'm doing here is implementing proxy support in one of my applications:

Code:

        '// PROXY SUPPORT
        If (formProxies.listBoxProxies.Items.Count > 0) Then

            '// VALIDATION

            For Each url As ListViewItem In listviewMain.CheckedItems

                    For Each proxyItem In formProxies.listBoxProxies.Items

                    Dim r As New Random
                    Dim randProxy As String = formProxies.listBoxProxies.GetItemText(formProxies.listBoxProxies.Items(r.Next(0, formProxies.listBoxProxies.Items.Count)))

                    '// RANDOM PROXY
                    Dim ProxyArray() As String = Split(randProxy.ToString, ":")
                    Dim proxyNumb As String = ProxyArray(0)
                    Dim proxyPort As String = ProxyArray(1)
                    Dim proxy As New WebProxy(proxyNumb & ":" & proxyPort)

                    '// USE PROXY WITH WEBCLIENT
                    Using wClient As New WebClient

                        wClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0")
                        wClient.Proxy = proxy

                        Try

                            Dim html As String = wClient.DownloadString(New Uri("http://www.site.com/?q=" & (url.SubItems(0).Text) & "&oq=" & (url.SubItems(0).Text) & "&IndexDataSource=F"))

                            formDebug.Show()
                            formDebug.txtDebug.Text = html.ToString

                            If (html.Contains("Maybe there are results in our other index")) Then
                                '// REMOVE THE URL FROM THE LISTVIEW
                                url.Checked = False
                            Else

                                '// CALL FUNCTION
                                Dim CF As String() = returnCF(html)

                                '// CLEANUP (REPLACE)
                                Dim cleaned1 As String = CF(0).ToString.Replace("</b></p>", "")
                                Dim cleaned2 As String = CF(1).ToString.Replace("</b></p>", "")

                                '// ADD TO LISTVIEWTRUST
                                ListBoxMain.Items.Add(url.SubItems(0).Text & " / " & cleaned1 & " / " & cleaned2)

                                '// REMOVE THE URL FROM THE LISTVIEW
                                url.Checked = False

                            End If

                        Catch ex As Exception
                            MessageBox.Show(ex.Message)
                        End Try

                    End Using

                Next

            Next

What happens is:

1) Depending on how many listView items are checked the code loops over and executes, once it does it's thing it un-checks the line so it doesn't keep looping (this works fine)

2) We grab a random proxy to use with the webClient.

The problems i have is:

1) The action with the proxies are heck of a slow compared to non proxies, is there anything i can do to speed it up? have i even coded it correctly lol

2) The program still loops the proxies even though the line gets un-checked, is there a way i can exit once the un-check has completed?

Thanks for any help guys!

Graham

Viewing all articles
Browse latest Browse all 27055

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>