PowerTCP Sockets for .NET

from $349.00
Available Platforms

Windows Forms Ping Code Example

See all PowerTCP Sockets for .NET Samples and Code Examples


The following C# example demonstrates a ping operation in a Windows Forms environment. The operation is executed asynchronously, without blocking the UI.


private void buttonPing_Click(object sender, EventArgs e)
    //This application has a User-Interface, which we do not want to block.
    //Start launches the specified method on a worker thread.
    ping1.Start(ping, new Dart.Sockets.IPEndPoint("www.dart.com", 0).Address);

private void ping(PingSlave slave, object address)
    //Ping the passed in address and marshal the results to the UI.
    //The ping contains no optional data, a 20 hop TTL and a 5 second timeout.
    //This function executes on a worker thread.
    ping1.Marshal(slave.GetEchoes((System.Net.IPAddress)address, null, 20, 5000, false));

private void ping1_Echo(object sender, EchoEventArgs e)
    //This event is raised when a GetEchoes result is passed to the UI.
    string results = "The following echoes were returned:\r\n";
    for (int i = 0; i < e.Echoes.Length; i++)
        results += e.Echoes[i].ToString() + "\r\n";


To download a trial please visit the PowerTCP Sockets for .NET product page.