protected void Button2_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
foreach (string result in ilist)//ilist里面是全部a标签链接的集合
{
string datetime = DateTime.Now.ToString("mmssffff");
Save(result, Server.MapPath(@"collection/" + datetime + ".html"));
/*
现在文章是可以采集下来,可是只是单线程模式,就是这个采集完才循环获取下一个链接在采集
这里怎么用多线程采集呢?
请高手帮帮忙,指点一下小弟!
*/
}
}
protected static void Button2_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath(@"collection/");
foreach (string result in ilist)
{
ThreadPool.QueueUserWorkItem(delegate(object param)
{
string datetime = DateTime.Now.ToString("mmssffff");
Save(result, string.Concat(rootPath,datetime,".html"));
});
}
}
//希望能看明白
protected void Button2_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
Thread td = null;
foreach (string result in ilist)
//ilist里面是全部a标签链接的集合
{
td = new Thread(new ParameterizedThreadStart(Run));
td.Start(result);
}
}
//for threading use
private void Run(object result)
{
string datetime = DateTime.Now.ToString("mmssffff");
Save(result.ToString(), Server.MapPath(@"collection/" + datetime + ".html"));
}