public void Collect(ProxyService proxyService) { LogManager log = new LogManager(); Stopwatch sw = new Stopwatch(); if (!lockObject) { lockObject = true; sw.Start(); log.Info($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 开始执行任务{Environment.NewLine}"); var RemoteData = proxyService.GetListByRemote(); log.Info($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 获取ip总数:{RemoteData.Count}{Environment.NewLine}"); Cache = proxyService.GetLiveData(RemoteData); log.Info($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 有效ip总数:{Cache.Count}{Environment.NewLine}"); File.AppendAllText(Environment.CurrentDirectory + "cache.json", JsonConvert.SerializeObject(Cache)); HandleTime = DateTime.Now; TotalCount = RemoteData.Count; ValidCount = Cache.Count; sw.Stop(); log.Info($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 总耗时:{sw.Elapsed}{Environment.NewLine}"); log.Info($"----------------------------------------------------{Environment.NewLine}"); lockObject = false; } File.WriteAllText(Environment.CurrentDirectory + "log.txt", "4\r\n"); }
static async Task /*void*/ Main(string[] args) { LogManager log = new LogManager(); log.Info("123"); ServicePointManager.DefaultConnectionLimit = 200; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); ProxyService proxyService = new ProxyService(); var models = proxyService.GetListByRemote(); Console.WriteLine("远程获取IP总数:" + models.Count); var newmodels = proxyService.GetLiveData(models); stopwatch.Stop(); Console.WriteLine("总数:" + newmodels.Count + " 耗时:" + stopwatch.Elapsed); foreach (var item in newmodels) { Console.WriteLine(item.ToString()); } Console.Read(); #region 延迟测试 //Proxy_89ip p = new Utils.Proxy_89ip(); //var ls = p.Parse(p.GetHtml()); //ls.ForEach(item => //{ // Task.Run(() => // { // Console.WriteLine(HttpHelper.ProxyCheck(ref item)); ; // }); //}); #endregion Console.Read(); }