The following example demonstrates asynchronously ping a host.
[C#]
using System; using aspNetPing; namespace ConsoleApplication1 { class Class1 { static void Main(string[] args) { IcmpClient icmp = new IcmpClient(); IAsyncResult result = icmp.BeginExecute( "www.yahoo.com", 4, -1, new AsyncCallback( MyCallback ), icmp ); Console.WriteLine( "done."); Console.ReadLine(); } static void MyCallback( IAsyncResult result ) { try { IcmpClient icmp = (IcmpClient)result.AsyncState; ReplyPacketCollection rpc = icmp.EndExecute( result ); Console.WriteLine( rpc.ToString() ); } catch( Exception ex ) { Console.WriteLine( ex.Message ); } } } }
[VB.NET]
Imports System Imports aspNetPing Module Module1 Sub Main() Dim icmp As New IcmpClient() Dim result As IAsyncResult = icmp.BeginExecute("www.yahoo.com", 4, -1, AddressOf MyCallback, icmp) Console.WriteLine("done.") Console.ReadLine() End Sub Sub MyCallback(ByVal result As IAsyncResult) Try Dim icmp As IcmpClient = CType(result.AsyncState, IcmpClient) Dim rpc As ReplyPacketCollection = icmp.EndExecute(result) Console.WriteLine(rpc.ToString()) Catch ex As Exception Console.WriteLine(ex.Message) End Try End Sub 'MyCallback End Module
Copyright - Contact: Webmaster