这个是开始扫描的Click代码部分,为什么这个扫描的速度非常的慢呢?
是写的有错误还是可以优化下呢?帮忙分析下,谢了~private void button2_Click(object sender, EventArgs e)
{
string aa = numericUpDown1.Text + "." + numericUpDown2.Text + "." + numericUpDown3.Text + ".";
int i = Int32.Parse(numericUpDown4.Text);
int j = Int32.Parse(numericUpDown5.Text);
progressBar1.Minimum = i;
progressBar1.Maximum = j; for (i = i; i < j; i++)
{
string bb = aa + i.ToString();
IPAddress myIP = IPAddress.Parse(bb);
try
{
IPHostEntry myHost = Dns.GetHostByAddress(myIP);
string cc = myHost.HostName.ToString();
richTextBox1.AppendText(bb + "-->" + cc + "\r");
}
catch (Exception ee)
{
richTextBox1.AppendText(bb + "-->" + ee.Message + "\r");
}
//下行设置进度条当前值
progressBar1.Value = i; }
是写的有错误还是可以优化下呢?帮忙分析下,谢了~private void button2_Click(object sender, EventArgs e)
{
string aa = numericUpDown1.Text + "." + numericUpDown2.Text + "." + numericUpDown3.Text + ".";
int i = Int32.Parse(numericUpDown4.Text);
int j = Int32.Parse(numericUpDown5.Text);
progressBar1.Minimum = i;
progressBar1.Maximum = j; for (i = i; i < j; i++)
{
string bb = aa + i.ToString();
IPAddress myIP = IPAddress.Parse(bb);
try
{
IPHostEntry myHost = Dns.GetHostByAddress(myIP);
string cc = myHost.HostName.ToString();
richTextBox1.AppendText(bb + "-->" + cc + "\r");
}
catch (Exception ee)
{
richTextBox1.AppendText(bb + "-->" + ee.Message + "\r");
}
//下行设置进度条当前值
progressBar1.Value = i; }
也可以指定进度条。
而且是个后台的多线程。
这个慢也许是因为你的程序在和网络上的资源通讯引起的。