【实例简介】
批量获取网站的标题
【实例截图】
【核心代码】
using HttpCodeLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
namespace 批量获取网站标题
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected List ItemsSource
{
get;
private set;
}
protected List CurrentCacheItemsSource
{
get;
private set;
}
private void button2_Click(object sender, EventArgs e)
{
stop = 0;
logg = 0;
if (listView1.Items.Count > 0)
{
button2.Enabled = false;
button5.Enabled = false;
button1.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button6.Visible = true;
button7.Visible = true;
progressBar1.Value = 0;
progressBar1.Visible = true;
progressBar1.Maximum = listView1.Items.Count;
//ThreadPool.SetMaxThreads(20, 20);//允许线程池中运行最多 20 个线程
for (int i = 0; i < listView1.Items.Count&&stop==0; i )
{
Thread th = new Thread(get_biaoti);
th.IsBackground = true;
string url = listView1.Items[i].SubItems[1].Text;
List list = new List();
list.Add(i.ToString());
list.Add(url);
th.Start(list);//可以执行进程
thCount ;
while (thCount >= maxThCount||logg==1)
{
Thread.Sleep(10);
Application.DoEvents();
}
// ThreadPool.QueueUserWorkItem(new WaitCallback(get_biaoti), list);
}
}
}
int thCount = 0;
int maxThCount = 20;
int logg = 0;
int stop = 0;
///
/// 获取标题
///
/// 页面内容
private void get_biaoti(object obj)
{
int i = (int.Parse((obj as List)[0]));
string url = (obj as List)[1];
string res = string.Empty;
if (jiekou == 1)
{
//string