So I have this code that I have written which checks all proxies in my ConcurrentQueue list, but I was wondering what if I just wanted to check if 1 proxy worked and then exit out of it? So I tried adding Boolean operators to test whether the proxyworking list had more than 1 proxy in it, but yet it still continued to check all the proxies.
System.Threading.Tasks.Parallel.ForEach(proxies, Sub(proxy)
Dim myProxy = New WebProxy(proxy)
Dim r As HttpWebRequest = HttpWebRequest.Create("http://www.google.com")
r.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36"
r.Timeout = 3000
r.Proxy = myProxy
Try
Using re As HttpWebResponse = r.GetResponse()
Console.WriteLine("Proxy Working: " & proxy & vbNewLine)
SyncLock workingProxies
workingProxies.Add(proxy)
End SyncLock
End Using
Catch ex As Exception
Console.WriteLine(ex.Message & " Proxy Not Working! " & proxy & vbNewLine)
End Try
End Sub)
That's the code I'm working with at the moment and when it runs the line workingProxies.Add(proxy) I want the tasks to stop and run a function.