I am developing an application that removes a website for Google + 1 shares, Facebook and tweets. I have a request method that takes a url and then disconnects and selects an account for each type of social networks.
This logic is as follows: -
- Take url
- Fulfills requests through a local / standard IP address until we get a speed limit / non-500
- On error
- Call
SelectNewProxy() , which iterates through the list of proxies and returns a random value (a good way to avoid access restrictions for your IP address). - Remove the bad proxy from the list to avoid re-selection.
- Start a timer that increments every second.
- When timer == 600 (10 minutes)
- Create a new
WebProxy and try again the requests for our local / standard IP address. - Reset timer
Rinse and repeat
The code is as follows:
public string Request(string action) { HttpWebRequest req; OnStatusChange(new MyArgs() { Message = "Status: Requesting..." }); string response = string.Empty; while (response.Equals(string.Empty) && proxy != null) { try { req = (HttpWebRequest)WebRequest.Create(action); req.Proxy = proxy; HandleUIMessages(action, proxy); response = new StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd(); } catch {
It is worth noting that I use ThreadPool , and each request runs its own thread in it. It seems that this will work, but I do not get the desired effect, the counter will reach “600” and set proxy = reset , but it seems to do it very briefly, perhaps only for the first thread that gets into it? Then timer_Elapsed is timer_Elapsed , and counter is reset. Could it be that the thread hit it by setting proxy = reset , and then, since counter now reset (no more than> = 600), all subsequent queues in the queue call SelectNewProxy() ? Feel that I am incoherent, but hopefully someone can understand what I'm trying to say, and if I am right in my assumptions, how can I guarantee that all streams will get proxy = reset and repeat our inital IP?
Any help is much appreciated!
Thankyou
source share