using System.Net.NetworkInformation;
异步调用:
private void button1_Click(object sender, EventArgs e)
{
Ping p1 = new Ping();
p1.PingCompleted += new PingCompletedEventHandler(this.PingCompletedCallBack);//设置PingCompleted事件处理程序
p1.SendAsync(this.textBox1.Text, null);
}
private void PingCompletedCallBack(object sender, PingCompletedEventArgs e)
{
if (e.Cancelled)
{
listBox1.Items.Add("Ping Canncel");
return;
}
if (e.Error != null)
{
listBox1.Items.Add(e.Error.Message);
return;
}
// StringBuilder sbuilder;
PingReply reply = e.Reply;
if (reply.Status == IPStatus.Success)
{
/*