110,537
社区成员
发帖
与我相关
我的任务
分享
private void hexing_check_Click(object sender, EventArgs e)
{
hexing_date.Rows.Clear();
hexing_name_select();
hexing_time.Enabled = true;
}
private void hexing_time_Tick(object sender, EventArgs e)
{
z++;
hexing_time.Tick += new EventHandler(hexing_click_select);
}
public void hexing_name_select()
{
hexing_line hexing = new hexing_line();
for (int i = 0; i < hexing.hexing_name.Count(); i++)
{
hexing_date.Rows.Add();
hexing_date.Rows[i].Cells[0].Value = hexing.hexing_name[i];
hexing_date.Rows[i].Cells[1].Value = hexing.hexing_ip[i];
}
}
public void hexing_thread()
{
int line_count = hexing_date.RowCount;//统计datagridview有多少行,就在下面设置多个线程
Thread[] line_PING = new Thread[line_count];
for (int a = 0; a < line_count; a++)
{
line_PING[a] = new Thread(new ParameterizedThreadStart(hexing_ping));
line_PING[a].Start(a);
}
}
public void hexing_ping(object obj)
{
int i = Convert.ToInt32(obj);
Ping pp = new Ping();
PingReply ppResult = pp.Send(Convert.ToString(hexing_date.Rows[i].Cells[1].Value), 10);
hexing_date.Rows[i].Cells[2].Value = ppResult.RoundtripTime.ToString();
hexing_date.Rows[i].Cells[3].Value = ppResult.Status.ToString();
hexing_date.Rows[i].Cells[4].Value = z;
}
public void hexing_click_select(object source, EventArgs e)
{
if (z > 100)//这里设置20次就不会卡,但是20以上就会了。。。。
{
hexing_time.Enabled = false;
int click_all = z - 1;
MessageBox.Show(click_all.ToString());
z = 0;
click_all = 0;
}
else
{
hexing_thread();
}
}
public void hexing_ping(object obj)
{
int i = Convert.ToInt32(obj);
Ping pp = new Ping();
PingReply ppResult = pp.Send(Convert.ToString(hexing_date.Rows[i].Cells[1].Value), 10);
hexing_date.Rows[i].Cells[2].Value = ppResult.RoundtripTime.ToString();
hexing_date.Rows[i].Cells[3].Value = ppResult.Status.ToString();
hexing_date.Rows[i].Cells[4].Value = z;
Thread th = new Thread(new ThreadStart(time_start));
th.Start();
// hexing_time.Stop();
// hexing_time.Start();
}
private void time_start()
{
hexing_time.Start();
}
private void hexing_check_Click(object sender, EventArgs e)
{
hexing_date.Rows.Clear();
hexing_name_select();
hexing_time.Enabled = true;
}
private void hexing_time_Tick(object sender, EventArgs e)
{
z++;
if (z > 100)//这里设置20次就不会卡,但是20以上就会了。。。。
{
hexing_time.Enabled = false;
int click_all = z - 1;
MessageBox.Show(click_all.ToString());
z = 0;
click_all = 0;
}
else
{
hexing_thread();
Application.DeEvents();
}
}
public void hexing_name_select()
{
hexing_line hexing = new hexing_line();
for (int i = 0; i < hexing.hexing_name.Count(); i++)
{
hexing_date.Rows.Add();
hexing_date.Rows[i].Cells[0].Value = hexing.hexing_name[i];
hexing_date.Rows[i].Cells[1].Value = hexing.hexing_ip[i];
}
}
public void hexing_thread()
{
int line_count = hexing_date.RowCount;//统计datagridview有多少行,就在下面设置多个线程
Thread[] line_PING = new Thread[line_count];
for (int a = 0; a < line_count; a++)
{
line_PING[a] = new Thread(new ParameterizedThreadStart(hexing_ping));
line_PING[a].Start(a);
}
}
public void hexing_ping(object obj)
{
int i = Convert.ToInt32(obj);
Ping pp = new Ping();
PingReply ppResult = pp.Send(Convert.ToString(hexing_date.Rows[i].Cells[1].Value), 10);
hexing_date.Rows[i].Cells[2].Value = ppResult.RoundtripTime.ToString();
hexing_date.Rows[i].Cells[3].Value = ppResult.Status.ToString();
hexing_date.Rows[i].Cells[4].Value = z;
}