和JS版功能相同,只是为了提高性能才用C#重写一次.N年前的代码,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace 网页关键词处理
{
public partial class keywords : Form
{
public keywords()
{
InitializeComponent();
}
private Thread t;
delegate void SetTextCallback(string text);
private void start_Click(object sender, EventArgs e){
if (start.Text.Equals("stop")) {
this.t.Abort();
start.Text = "start";
}else{
this.t = new Thread(new ThreadStart(this.threadsafe));
this.t.Start();
start.Text = "stop";
}
}
private void threadsafe() {
//获取数据库连接
string _sha1 = "";
string _url = "";
if (url.Text.Trim().Equals(""))
{
MySqlConnection conn = new MySqlConnection("server=" + db_servers.Text.Trim() + ";user=" + db_uid.Text.Trim() + ";database=" + db_db.Text.Trim() + ";port=3306;password=" + db_pwd.Text.Trim() + ";charset=utf8");
try
{
conn.Open();
MySqlCommand cmd = new MySqlCommand("SELECT url_sha1,url_link FROM url ORDER BY url_update,url_error ASC LIMIT 1", conn);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) {
_sha1 = rdr.GetString(0).Trim();
_url = rdr.GetString(1).Trim();
}
rdr.Close();
cmd.Dispose();
rdr.Dispose();
rdr = null;
cmd = null;
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Dispose();
conn = null;
}else {
_sha1 = "";
_url = url.Text.Trim();
}
show("访问:"+_url);
try
{
html h = new html(gethttp(_url));
string title = h.Title;
string body = h.Body;
MySqlConnection conn = new MySqlConnection("server=" + db_servers.Text.Trim() + ";user=" + db_uid.Text.Trim() + ";database=" + db_db.Text.Trim() + ";port=3306;password=" + db_pwd.Text.Trim() + ";charset=utf8");
conn.Open();
MySqlCommand cmd = new MySqlCommand("UPDATE url