/// <summary> /// Releases the proxy. /// </summary> /// <param name="proxy">Proxy to release</param> private void ReleaseProxy(ref Proxy proxy) { for (int i = 0; i < proxies.Count; i++) { Utils.Pair <Proxy, bool> cur = proxies[i]; if (cur.item2 && cur.item1.Equals(proxy)) { lock (theLock) { cur.item2 = false; } break; } } }
/// <summary> /// Randomly selects a proxy from proxy list. /// </summary> /// <returns>Proxy to use.</returns> private Proxy GetRandomProxy() { int attempts = 0; do { int index = random.Next(0, proxies.Count); Utils.Pair <Proxy, bool> pair = proxies[index]; lock (theLock) { if (!pair.item2) { pair.item2 = true; return(pair.item1); } } }while (++attempts < 20); return(null); }