日期:2014-05-17 浏览次数:21101 次
private void button3_Click(object sender, EventArgs e)
{
//IPAddress address = IPAddress.Parse(Convert.ToString(dataGridView1.Rows[i].Cells[1].Value));
Thread thread = new Thread(new ThreadStart(_pingThread));
thread.IsBackground = true;
thread.Start();
}
private void _pingThread()
{
Ping ping = new Ping();
ping.PingCompleted += new PingCompletedEventHandler(_myPing_PingCompleted);
for(int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (Convert.ToString(dataGridView1.Rows[i].Cells[1].Value) != "")
{
string _ipAddress = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value);
//每一行的datagridview中的第二格都有IP地址
PingReply result = ping.Send(_ipAddress);
if (result.Status != IPStatus.Success)
{
dataGridView1.Rows[i].Cells[3].Value = result.RoundtripTime.ToString();
}
}
}
}