There are two lists
var proxy = new List<string>(); // 4 прокси var urls = new List<string>(); // 100 урлов I am using Parallel.For to implement multithread. The question now is that each proxy only makes 25 requests (25 * 4 = 100). As I see the best option is to divide the list into urls.Count/proxy.Count . However, it may be that if the collection is larger, it turns out that the same thread with one proxy can take data from the collection several times. How to be?
Parallel.ForEach(Partitioner.Create(0, urls.Count, urls.Count / proxy.Count), new ParallelOptions { MaxDegreeOfParallelism = 10 }, range => { for (int i = range.Item1; i < range.Item2; i++) { .... } });
range.AsParallel().WithDegreeOfParallelism(4).ForAll(...). Why do you need to share the collection exactly? - Raider