|
启动:- OutputInfo("开始启动操作线程...");
- for (int i = 0; i <= ThreadNumber; i++)//5个线程
- {
- ThreadStart threadStart = new ThreadStart(StartGo);
- thread = new Thread(threadStart);
- thread.Name = i.ToString();
- ThL.Add(thread);
- thread.Start();
- }
复制代码 函数:- private void StartGo()
- {
- string URL = "";
- string proxy = "";
- string htmlcode = "";
- while (Proxylist.Count != 0)
- {
- for (int i = 0; i < Proxylist.Count; i++)//循环代理
- {
-
- lock (tLock)
- {
- if (URL == "")
- {
- URL = Linkslist[0];//链接列表
- Linkslist.Remove(URL);
- }
- proxy = Proxylist[0];//代理列表
- Proxylist.Remove(proxy);
- Proxy_label.Text = Proxylist.Count.ToString();
- }//loo
- htmlcode = GetHtmlCode(URL, proxy);
- OutputInfo("线程[ " + Thread.CurrentThread.Name + " ] 操作" + proxy + " / " + GetViewkey(URL));
- if (htmlcode.Length < 30)
- {
- OutputInfo("错误:" + proxy + " > " + htmlcode);
-
- proxy = "";
- }
- else if (GetContent(1, htmlcode) == "")
- {
- OutputInfo("错误:" + proxy + "失效,继续下一个代理! > ");
-
- proxy = "";
- }
- else
- {
- ModData(GetContent(1, htmlcode), GetContent(0, htmlcode), GetViewkey(htmlcode).Trim());//存入数据库
- proxy = "";
- // Linkslist.Remove(URL);
- LinksData_label.Text = Linkslist.Count.ToString();
- URL = "";
- }
-
-
- }//for
-
- }//w
- OutputInfo("代理地址已经使用完!");
- }
复制代码 程序运行后。
前5个线程和下5个线程相隔有半分钟甚至更长。是我代码哪里的问题啊。帮忙修改下。
我的思路是:
循环代理地址取网页代码。成功换代理及下一个网页。不成功换代理继续这个网页
|
|