public void Start() { foreach (string website in webSites) { var thread = new DownloadThread(website); thread.DownloadThread_Completed += CheckCompleted; thread.Start(); threads.Add(thread); } }
/// <summary> /// 获取代理列表 /// </summary> /// <param name="url"></param> /// <returns></returns> public static void Downloading(DownloadThread downloader) { try { var httpHelper = new HttpHelper(); httpHelper.IsUseDefaultProxy = false; if (Config.LocalSetting.HttpOption != null) { httpHelper.HttpOption = Config.LocalSetting.HttpOption; } else { httpHelper.HttpOption.Timeout = 60 * 1000; } string result = ""; if (Config.LocalSetting.IsUseSystemProxy) { result = httpHelper.GetHtml(downloader.Url); } else { result = httpHelper.GetHtml(downloader.Url); } string line = result; var regex = new Regex(Config.RegexProxy); MatchCollection matches = regex.Matches(line); downloader.Description = "The downloading thread " + downloader.thread.ManagedThreadId + " is downloading.Proxies count:" + matches.Count; Config.ConsoleEx.Debug(downloader.Description); for (int i = 0; i < matches.Count; i++) { var model = new ProxyServer(); model.proxy = matches[i].Groups["Proxy"].Value; model.port = int.Parse(matches[i].Groups["Port"].Value); ProxyServer cloudProxy = CloudProxyData.Get(model.proxy, model.port); if (null != cloudProxy) { ProxyDataAddRow(cloudProxy); } else { ProxyDataAddRow(model); } } downloader.Description = "The downloading thread " + downloader.thread.ManagedThreadId + " download completed."; Config.ConsoleEx.Debug(downloader.Description); } catch (WebException webEx) { Config.ConsoleEx.Debug(webEx); } catch (Exception ex) { Config.ConsoleEx.Debug(ex); } finally { } }