Home | Contact Us | Download | Support | Purchase | Products


Product List
 
  "Wow! The testimonials weren't kidding about the support."
Morgan Fears
 
More
Testimonies

Ping using Events

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

 

 

 

 

 

 



The box is not shipped. aspNetPing is a downloadable product.