public void singleThreadScan()
{
string filePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"弱口令.txt";//获取文本物理路径
using (StreamReader sr = new StreamReader(filePath, Encoding.Default))//准备流读文件内容
{
string pwd = "";
while (!Iscounted)//Iscounted 标志 初始 false 循环读文本行
{
if ((pwd = sr.ReadLine()) != null)
{
// mr = new ManualResetEvent(false);
lbox_msg.Items.Add(count + "............" + pwd);
lbox_msg.SelectedIndex = i;
i++;
th = new Thread(startConnectDB);
th.IsBackground = true;
th.Start(pwd);
th.Join(0);
//startConnectDB(pwd);//单线程调用
//线程池调用
//ThreadPool.SetMaxThreads(1000, 1000);
//ThreadPool.QueueUserWorkItem(new WaitCallback(startConnectDB), pwd);
//mr.WaitOne();
//count++;
}
}
MessageBox.Show("end");
}
}
public void startConnectDB(object pw)
{
string pwd = (string)pw;
try
{
IPAddress[] ip = Dns.GetHostAddresses(txt_ServerName.Text.Trim());//读取文本框的服务IP
//组成字条串
string connStr = Conn.conn + pwd;
connStr = connStr.Replace("@{ip}", ip[0].ToString());
using (SqlConnection conn = new SqlConnection(connStr))
{
endTime = DateTime.Now;
lb_endtime.Text = endTime.ToLongTimeString();
Timespan();
conn.Open();
if (conn.State == ConnectionState.Open)
{
MessageBox.Show("cur");
txt_pwd.Text = pwd;
Iscounted = true;
}
if (th.IsAlive)
{
th.Abort();//kill线程
}
}
}
catch (Exception)
{
;
}
为什么这样还占用这么大的CPU资源
|