多线程采集到一定数据量卡住不动,贴代码求助大神

yeweit6 2013-02-24 11:02:09
                
foreach (string url in queue) //遍历,线程池
{
ThreadPool.QueueUserWorkItem(new WaitCallback(CheckFile), url);
}


void CheckFile(object url) //数据传入
{
foreach (string str in filenameArr)
{
try
{
string strUrlFile2 = UriFile(url.ToString(), str);
toollblUrl.Text = strUrlFile2;
HttpWebResponse response = Com.WebResponse(strUrlFile2);
if (response.StatusCode == HttpStatusCode.OK && response.ContentLength > int.Parse(txtSize.Text) * 1024 && response.ContentType.ToLower() != "text/html")
{
txtResult.Text += response.ResponseUri + response.Server + response.Method + response.StatusCode + response.ContentLength + "\r\n";
File.AppendAllText(path + "Data\\success.txt", DateTime.Now + "\t" + response.ResponseUri + "\t" + response.ContentLength.ToString() + "\r\n");

}
}
catch (Exception ex)
{
//textBox2.Text += ex.Message + "\r\n";
}

}

public static HttpWebResponse WebResponse(string strUrlFile)
{
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strUrlFile);
req.Method = "HEAD";
req.Timeout = 3000;
req.ProtocolVersion = HttpVersion.Version11;
req.AllowAutoRedirect = false;
req.Accept = "*/*";
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
return res;
}
catch (Exception)
{
}
return null;
}
...全文
255 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yeweit6 2013-02-25
  • 打赏
  • 举报
回复
引用 8 楼 lzxue1989 的回复:
引用 7 楼 yeweit6 的回复:引用 6 楼 lzxue1989 的回复: 你这个取不别人的数据 你的IP不断去访问服务器, 别人服务器是不是做了限制的, 你往这方面去查下 但是我不是设置timeout了吗 如果别人服务器把你的ip屏蔽了, 你通过浏览器来打开其网址都打不开的, 你怎么可能取到数据呢, 只要卡起不动了,你就断点进去看看, 是不是没……
如果是这样的话,timeout没有效的话,应该怎么办呢
csdn_风中雪狼 2013-02-25
  • 打赏
  • 举报
回复
引用 7 楼 yeweit6 的回复:
引用 6 楼 lzxue1989 的回复: 你这个取不别人的数据 你的IP不断去访问服务器, 别人服务器是不是做了限制的, 你往这方面去查下 但是我不是设置timeout了吗
如果别人服务器把你的ip屏蔽了, 你通过浏览器来打开其网址都打不开的, 你怎么可能取到数据呢, 只要卡起不动了,你就断点进去看看, 是不是没有取数据
yeweit6 2013-02-25
  • 打赏
  • 举报
回复
引用 6 楼 lzxue1989 的回复:
你这个取不别人的数据 你的IP不断去访问服务器, 别人服务器是不是做了限制的, 你往这方面去查下
但是我不是设置timeout了吗
csdn_风中雪狼 2013-02-25
  • 打赏
  • 举报
回复
你这个取不别人的数据 你的IP不断去访问服务器, 别人服务器是不是做了限制的, 你往这方面去查下
yeweit6 2013-02-25
  • 打赏
  • 举报
回复
引用 11 楼 wonderfuly 的回复:
queue 里面是不是太多了。你这种写法有问题的。 foreach (string url in queue) //遍历,线程池 { ThreadPool.QueueUserWorkItem(new WaitCallback(CheckFile), url); }
queue有那应该在什么控制范围呢
游戏人间 2013-02-25
  • 打赏
  • 举报
回复
queue 里面是不是太多了。你这种写法有问题的。 foreach (string url in queue) //遍历,线程池 { ThreadPool.QueueUserWorkItem(new WaitCallback(CheckFile), url); }
puler 2013-02-24
  • 打赏
  • 举报
回复
那边双江的新闻还没看完,帮顶先
yeweit6 2013-02-24
  • 打赏
  • 举报
回复
求助大牛神一般的回复
yeweit6 2013-02-24
  • 打赏
  • 举报
回复
引用 3 楼 tiana0 的回复:
看看内存和cpu的使用情况呗
内存和cpu使用率还有很多富裕
三五月儿 2013-02-24
  • 打赏
  • 举报
回复
看看内存和cpu的使用情况呗
startstartsvip 2013-02-24
  • 打赏
  • 举报
回复
引用 1 楼 puler 的回复:
那边双江的新闻还没看完,帮顶先
李双江又被儿子坑了

110,532

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧