public void Merge(Scraper scraper) { foreach (Trade trade1 in scraper.tradeList) { foreach (Trade trade2 in tradeList) { if (trade1.id == trade2.id) { break; } } tradeList.Add(trade1); //trade1 is the external Scraper, this code maybe needs clarifying, or should be done in a database class instead.. } }
static void Main(string[] args) { cookie = new CookieContainer(); cookie.Add(new Cookie("__cfduid", "db3885975dd994db43565d6bd785ef7981357764858", "/", ".tf2outpost.com")); cookie.Add(new Cookie("trade", "7613554", "/", "www.tf2outpost.com")); cookie.Add(new Cookie("userid", "262200", "/", "www.tf2outpost.com")); cookie.Add(new Cookie("token", "b580e2c50a70d120064cfb6d28c983b5", "/", "www.tf2outpost.com")); cookie.Add(new Cookie("session", "5cb4978cc373dc0e52f45f09a9768b69", "/", "www.tf2outpost.com")); cookie.Add(new Cookie("intergi", "1", "/", "www.tf2outpost.com")); masterScraper = new Scraper(); scraperList = new List<Scraper>(); List<Task> threadList = new List<Task>(); for (pageNum = 1; pageNum <= 20; pageNum++) { //Thread t = new Thread(delegate() { scrapeFrontPage(pageNum); }); Task t = new Task(() => scrapeFrontPage(pageNum)); threadList.Add(t); t.Start(); //Thread.Sleep(10); } for(int i = 0; i < threadList.Count; i++) { while (true) { if (threadList[i].Status == TaskStatus.Running) { Thread.Sleep(10); } else { break; // out of infinite while loop } } } foreach (Scraper scraper in scraperList) { masterScraper.Merge(scraper); } Console.WriteLine(masterScraper.tradeList.Count()); Console.ReadLine(); }