public void Request(object i) { //当前线程索引 int currThreadIndex = (int)i; while (true) { //抓取目标数量为0 if (Targets.Count == 0) { _taskIsSleep[currThreadIndex] = true; //如果全部休眠 if (_taskIsSleep.Any(c => c == true)) { Debug.Write("爬取结束!"); break; } Thread.Sleep(2000); continue; } _taskIsSleep[currThreadIndex] = false; if (Targets.Count == 0) { continue; } //取目标 var target = Targets.Dequeue(); //创建请求对象 var request = InfectionManager.CreateRequest(new InfectionConfig() { Url = target.Url }); //获取请求响应 var pagePathogen = InfectionManager.GetResponse(request); if (pagePathogen != null) { //页面解析 _processor.PageProcess(pagePathogen); //是否传递附加参数 if (target.ExtraObj != null) { pagePathogen.AddResult("extraObj", target.ExtraObj); } //数据解析 _processor.DataProcess(pagePathogen.ResultList); } } }