PingCheckerAsync
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation;
namespace MyApp.Utility
{
<summary>
</summary>
public class PingCheckerAsync
{
#region 変数
<summary>
</summary>
Ping ping = null;
<summary>
</summary>
<example>
=
==
===
</example>
public event PingCompletedEventHandler PingCompleted = null;
#endregion
#region コンストラクタ
<summary>
</summary>
public PingCheckerAsync()
{
this.ping = new Ping();
this.ping.PingCompleted += new PingCompletedEventHandler(ping_PingCompleted);
}
#endregion
#region メソッド
#region Ping完了処理
<summary>
</summary>
<param name="sender"></param>
<param name="e"></param>
void ping_PingCompleted(object sender, PingCompletedEventArgs e)
{
this.PingCompleted(sender, e);
}
#endregion
#region Pingをキャンセルする
<summary>
</summary>
public void SendAsyncCancel()
{
this.ping.SendAsyncCancel();
}
#endregion
#region Pingを送信する
<summary>
</summary>
<param name="hostNameOrAddress"></param>
<param name="timeOut"></param>
public void SendAsync(string hostNameOrAddress, Int32 timeOut)
{
if (string.IsNullOrEmpty(hostNameOrAddress))
{
throw new ArgumentException("param:[hostNameOrAddress]がnullまたは空文字");
}
if (timeOut < 0)
{
throw new ArgumentException("param:[timeOut]が0未満");
}
System.Net.NetworkInformation.PingOptions opts = new System.Net.NetworkInformation.PingOptions(64, true);
byte[] bs = System.Text.Encoding.ASCII.GetBytes(new string('A', 32));
this.ping.SendAsync(hostNameOrAddress, timeOut, bs, opts, null);
}
#endregion
#endregion
}
}