前台:一个按钮
后台:
private void button4_Click(object sender, EventArgs e)
{
for (int i = 30000; i < 30020; i++)
{
WaitCallback wait = new WaitCallback(DownLoadThreadPool2);
ThreadPool.QueueUserWorkItem(wait, i);
}
}
private void DownLoadThreadPool2(object obj)
{
try
{
using (WebClient client=new WebClient())
{
int i = Convert.ToInt32(obj);
client.DownloadFile(@"http://job.cnblogs.com/offer/" + i + "/", @"d:move" + i + ".html");
this.Invoke(new Action(delegate() {
this.textBox1.AppendText("第" + i + "个帖子已经下载完成
");
}));
}
}
catch (Exception ex)
{ }
}