The following example demonstrates how to ping indefinately, using the event driven model.
[C#]
using System; using aspNetPing; namespace ConsoleApplication1 { class Class1 { [STAThread] static void Main(string[] args) { IcmpClient icmp = new IcmpClient(); //wire up the recieved event icmp.Received += new ReceivedEventHandler( ICMP_OnReceived ); //ping indefinately icmp.Execute( "www.yahoo.com", -1 ); Console.WriteLine( "done."); Console.ReadLine(); } static void ICMP_OnReceived( object sender, ReceivedEventArgs e ) { ReplyPacket packet = e.Packet; Console.WriteLine("Reply from: " + packet.Source.ToString() + ", seq: " + packet.SequenceNumber.ToString() + ", time = " + packet.ReplyTime.ToString() + "ms"); } } }
[VB.NET]
Imports System Imports aspNetPing Module Module1 Sub Main() Dim icmp As New IcmpClient() 'wire up the recieved event AddHandler icmp.Received, AddressOf ICMP_OnReceived 'ping indefinately icmp.Execute("www.yahoo.com", -1) Console.WriteLine("done.") Console.ReadLine() End Sub Sub ICMP_OnReceived(ByVal sender As Object, ByVal e As ReceivedEventArgs) Dim packet As ReplyPacket = e.Packet Console.WriteLine(("Reply from: " + packet.Source.ToString() + ", seq: " + packet.SequenceNumber.ToString() + ", time = " + packet.ReplyTime.ToString() + "ms")) End Sub 'ICMP_OnReceived End Module
Copyright 2003 - Contact: Webmaster