I am building a scraper. My goal is to launch X-browsers (where X is the number of threads) and start cleaning the list of URLs with each of them by splitting this list into X-parts.
I decided to use 3 streams (3 browsers) with a list of 10 URLs.
Question. How to split each task between browsers as follows:
Browser1 resets items in the list from 0 to 3
Browser2 resets items in a list of 4 to 7
Browser3 resets items in the list from 8 to 10
All browsers should work simultaneously with clearing the submitted list of URLs.
I already have this BlockingCollection :
BlockingCollection<Action> _taskQ = new BlockingCollection<Action>(); public Multithreading(int workerCount) {
It can be used as follows:
Multithreading multithread = new Multithreading(3); //3 threads foreach(string url in urlList){ multithread.EnqueueTask(new Action(() => { startScraping(browser1); //or browser2 or browser3 })); }
I need to create browser instances before , because I do not want to launch a new browser with each thread.
source share