PingCompletedEventArgs クラス
アセンブリ: System (system.dll 内)
構文
このクラスのインスタンスは、SendAsync の呼び出しが完了すると呼び出される PingCompletedEventHandler メソッドに渡されます。SendAsync メソッドは、ICMP (インターネット コントロール メッセージ プロトコル) エコー要求を非同期的に送信し、対応する ICMP エコー応答メッセージを待ち受けます。Reply プロパティには、ICMP エコー要求の結果が格納されます。
ICMP エコー要求を非同期的に送信するコード例に次に示します。
using System; using System.Text; using System.Net; using System.Net.NetworkInformation; using System.ComponentModel; using System.Threading; namespace Examples.System.Net.NetworkInformation.PingTest { public class PingExample { public static void Main (string[] args) { if (args.Length == 0) throw new ArgumentException ("Ping needs a host or IP Address."); string who = args[0]; AutoResetEvent waiter = new AutoResetEvent (false); Ping pingSender = new Ping (); // When the PingCompleted event is raised, // the PingCompletedCallback method is called. pingSender.PingCompleted += new PingCompletedEventHandler (PingCompletedCallback); // Create a buffer of 32 bytes of data to be transmitted. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes (data); // Wait 12 seconds for a reply. int timeout = 12000; // Set options for transmission: // The data can go through 64 gateways or routers // before it is destroyed, and the data packet // cannot be fragmented. PingOptions options = new PingOptions (64, true); Console.WriteLine ("Time to live: {0}", options.Ttl); Console.WriteLine ("Don't fragment: {0}", options.DontFragment); // Send the ping asynchronously. // Use the waiter as the user token. // When the callback completes, it can wake up this thread. pingSender.SendAsync(who, timeout, buffer, options, waiter); // Prevent this example application from ending. // A real application should do something useful // when possible. waiter.WaitOne (); Console.WriteLine ("Ping example completed."); } public static void PingCompletedCallback (object sender, PingCompletedEventArgs e) { // If the operation was canceled, display a message to the user. if (e.Cancelled) { Console.WriteLine ("Ping canceled."); // Let the main thread resume. // UserToken is the AutoResetEvent object that the main thread // is waiting for. ((AutoResetEvent)e.UserState).Set (); } // If an error occurred, display the exception to the user. if (e.Error != null) { Console.WriteLine ("Ping failed:"); Console.WriteLine (e.Error.ToString ()); // Let the main thread resume. ((AutoResetEvent)e.UserState).Set(); } PingReply reply = e.Reply; DisplayReply (reply); // Let the main thread resume. ((AutoResetEvent)e.UserState).Set(); } public static void DisplayReply (PingReply reply) { if (reply == null) return; Console.WriteLine ("ping status: {0}", reply.Status); if (reply.Status == IPStatus.Success) { Console.WriteLine ("Address: {0}", reply.Address.ToString ()); Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime); Console.WriteLine ("Time to live: {0}", reply.Options.Ttl); Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment); Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length); } } } }
System.EventArgs
System.ComponentModel.AsyncCompletedEventArgs
System.Net.NetworkInformation.PingCompletedEventArgs
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
PingCompletedEventArgs プロパティ
パブリック プロパティ
名前 | 説明 | |
---|---|---|
Cancelled | 非同期操作がキャンセルされたかどうかを示す値を取得します。 ( AsyncCompletedEventArgs から継承されます。) | |
Error | 非同期操作中に発生したエラーを示す値を取得します。 ( AsyncCompletedEventArgs から継承されます。) | |
Reply | ICMP (インターネット コントロール メッセージ プロトコル) エコー要求メッセージの送信と、対応する ICMP エコー応答メッセージの受信を行う処理について記述したデータが格納されているオブジェクトを取得します。 | |
UserState | 非同期タスクの一意の識別子を取得します。 ( AsyncCompletedEventArgs から継承されます。) |
PingCompletedEventArgs メソッド
パブリック メソッド
名前 | 説明 | |
---|---|---|
Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) | |
GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) | |
GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) | |
ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) | |
ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
名前 | 説明 | |
---|---|---|
Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) | |
MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) | |
RaiseExceptionIfNecessary | 非同期操作が失敗した場合は、ユーザー指定の例外を発生させます。 ( AsyncCompletedEventArgs から継承されます。) |
PingCompletedEventArgs メンバ
PingCompletedEventArgs データ型で公開されるメンバを以下の表に示します。
パブリック プロパティ
名前 | 説明 | |
---|---|---|
Cancelled | 非同期操作がキャンセルされたかどうかを示す値を取得します。(AsyncCompletedEventArgs から継承されます。) | |
Error | 非同期操作中に発生したエラーを示す値を取得します。(AsyncCompletedEventArgs から継承されます。) | |
Reply | ICMP (インターネット コントロール メッセージ プロトコル) エコー要求メッセージの送信と、対応する ICMP エコー応答メッセージの受信を行う処理について記述したデータが格納されているオブジェクトを取得します。 | |
UserState | 非同期タスクの一意の識別子を取得します。(AsyncCompletedEventArgs から継承されます。) |
名前 | 説明 | |
---|---|---|
Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) | |
GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) | |
GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) | |
ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) | |
ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
名前 | 説明 | |
---|---|---|
Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) | |
MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) | |
RaiseExceptionIfNecessary | 非同期操作が失敗した場合は、ユーザー指定の例外を発生させます。 (AsyncCompletedEventArgs から継承されます。) |
- PingCompletedEventArgsのページへのリンク