GXDN: Gurux Developer Network
GuruxPing component
Gurux provides you with a sample code to show, how to use the component. For further information, contact our product support.

[VB.Net example]
Option Explicit On
Friend Class Form1
	Inherits System.Windows.Forms.Form

    ''' <summary>
    ''' Closes Ping connection.
    ''' </summary>
    ''' <param name="eventSender"></param>
    ''' <param name="eventArgs"></param>
	Private Sub CloseBtn_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CloseBtn.Click
        Try
            GXPing1.Close()
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
    End Sub
	
    ''' <summary>
    ''' Disables buttons on load.
    ''' </summary>
    ''' <param name="eventSender"></param>
    ''' <param name="eventArgs"></param>
	Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Try
            If GXPing1.IsOpen Then
                OnMediaStateChange(GuruxPing.GX_MEDIA_STATE_CHANGE.GX_MEDIA_STATE_CHANGE_OPEN)
            Else
                OnMediaStateChange(GuruxPing.GX_MEDIA_STATE_CHANGE.GX_MEDIA_STATE_CHANGE_CLOSE)
            End If
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' Closes media, when the window is closed.
    ''' </summary>
    ''' <param name="eventSender"></param>
    ''' <param name="eventArgs"></param>
	Private Sub Form1_FormClosing(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            GXPing1.Close()
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
    End Sub
	
    ''' <summary>
    ''' Closes media.
    ''' </summary>
    ''' <param name="eventSender"></param>
    ''' <param name="eventArgs"></param>
	Private Sub Form1_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Try
            GXPing1.Close()
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' Shows occurred errors.
    ''' </summary>
    ''' <param name="ErrorInfo"></param>
    Private Sub OnError(ByVal ErrorInfo As String)
        Try
            MessageBox.Show(ErrorInfo)
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' To improve the performance of communication, the GXPing component can send 
    ''' an error notification, directly through its own thread. Windows, however, 
    ''' does not allow all UI components to be used from another thread. As the 
    ''' updated notifications cannot be shown automatically, the application 
    ''' itself has to show them. This is done by using BeginInvoke function, 
    ''' as shown below.
    ''' </summary>
    ''' <param name="eventSender"></param>
    ''' <param name="eventArgs"></param>
    Private Sub GXPing1_OnError(ByVal eventSender As System.Object, ByVal eventArgs As AxGuruxPing.IGXPingEvents_OnErrorEvent) Handles GXPing1.OnError
        Try
            Dim args() As Object = {eventArgs.errorInfo}
            Me.BeginInvoke(New GuruxPing.IGXPingEvents_OnErrorEventHandler(AddressOf OnError), args)
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' Media state has changed.
    ''' </summary>
    ''' <param name="State"></param>
  Private Sub OnMediaStateChange(ByVal State As GuruxPing.GX_MEDIA_STATE_CHANGE)
    Try
      If ((State & GuruxPing.GX_MEDIA_STATE_CHANGE.GX_MEDIA_STATE_CHANGE_OPEN) <> 0) Then
        TimeOutTB.ReadOnly = CountTB.ReadOnly = HostName.ReadOnly = True
      ElseIf ((State & GuruxPing.GX_MEDIA_STATE_CHANGE.GX_MEDIA_STATE_CHANGE_CLOSE) <> 0) Then
        TimeOutTB.ReadOnly = CountTB.ReadOnly = HostName.ReadOnly = False
      End If
    Catch Ex As Exception
      MessageBox.Show(Ex.Message)
    End Try
  End Sub

  ''' <summary>
  ''' To improve the performance of communication, the GXPing component can send a notification 
  ''' of a changed media state, directly through its own thread. Windows, however, does not allow 
  ''' all UI components to be used from another thread. As the updated notifications cannot be 
  ''' shown automatically, the application itself has to show them. This is done by using 
  ''' BeginInvoke function, as shown below.
  ''' </summary>
  ''' <param name="eventSender"></param>
  ''' <param name="eventArgs"></param>
  Private Sub GXPing1_OnMediaStateChange(ByVal eventSender As System.Object, ByVal eventArgs As AxGuruxPing.IGXPingEvents_OnMediaStateChangeEvent) Handles GXPing1.OnMediaStateChange
  Try
  Dim args() As Object = {eventArgs.state}
  Me.BeginInvoke(New GuruxPing.IGXPingEvents_OnMediaStateChangeEventHandler(AddressOf OnMediaStateChange), args)
  Catch Ex As Exception
  MessageBox.Show(Ex.Message)
  End Try
  End Sub

  ''' <summary>
  ''' Ping selected host.
  '''
  </summary>
  ''' <param name="eventSender"</param>
  ''' <param name="eventArgs"</param>
  ''' 
  Private Sub PingBtn_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles PingBtn.Click
  Try
  LogTB.Text = ""
  GXPing1.HostName = HostName.Text
  GXPing1.Timeout = CInt(TimeOutTB.Text)
  GXPing1.Count = CInt(CountTB.Text)
  GXPing1.Ping()
  Catch Ex As Exception
  MessageBox.Show(Ex.Message)
  End Try
  End Sub
  
  ''' <summary>
  ''' New data from GXPing is received.
  ''' </summary>
  ''' <param name="data">Received data.</param>
  ''' <param name="senderInfo">Sender of the data. In Ping this is empty.</param>
  Private Sub OnPing(ByVal State As GuruxPing.GX_PING_STATE, ByVal SentCount As Integer, ByVal LostCount As Integer, ByVal LastTime As Integer, ByVal AverageTime As Integer, ByVal MinimumTime As Integer, ByVal MaximumTime As Integer)
    Try
      If State = GuruxPing.GX_PING_STATE.GX_PING_STATE_OK Then
        LogTB.Text += LastTime.ToString() + "/" + AverageTime.ToString() + System.Environment.NewLine
        MinTB.Text = MinimumTime.ToString()
        MaxTB.Text = MaximumTime.ToString()
        AverageTB.Text = AverageTime.ToString()
      End If
    Catch Ex As Exception
      MessageBox.Show(Ex.Message)
    End Try
  End Sub
  
  ''' <summary>
  ''' To improve the performance of communication, the GXPing component can send a notification 
  ''' of data received, directly through its own thread. Windows, however, does not allow all UI 
  ''' components to be used from another thread. As the updated notifications cannot be shown 
  ''' automatically, the application itself has to show them. This is done by using 
  ''' BeginInvoke function, as shown below.
  ''' </summary>
  ''' <param name="eventSender"></param>
  ''' <param name="eventArgs"></param>
  Private Sub GXPing1_OnPing(ByVal sender As System.Object, ByVal e As AxGuruxPing._IGXPingEvents_OnPingEvent) Handles GXPing1.OnPing
    Try
      Dim args() As Object = {e.state, e.sentCount, e.lostCount, e.lastTime, e.averageTime, e.minimumTime, e.maximumTime}
      Me.BeginInvoke(New GuruxPing._IGXPingEvents_OnPingEventHandler(AddressOf OnPing), args)
    Catch Ex As Exception
      MessageBox.Show(Ex.Message)
    End Try
  End Sub

    ''' <summary>
    ''' Shows GXPing media properties.
    ''' </summary>
    ''' <param name="eventSender"></param>
    ''' <param name="eventArgs"></param>
    Private Sub PropertiesBtn_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles PropertiesBtn.Click
        Try
            GXPing1.Properties(Me.Handle.ToInt32)
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
    End Sub
End Class

[C# example]
using System;
using System.Windows.Forms;
namespace GXPingSample
{
    internal partial class Form1 : System.Windows.Forms.Form
    {		
      /// <summary>
      /// Closes Ping connection.
      /// </summary>
      /// <param name="eventSender"></param>
      /// <param name="eventArgs"></param>
      private void CloseBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
      {
          try
          {
              GXPing1.Close();
          }
          catch (Exception Ex)
          {
              MessageBox.Show(Ex.Message);
          }
      }
	
      /// <summary>
      /// Disables buttons.
      /// </summary>
      /// <param name="eventSender"></param>
      /// <param name="eventArgs"></param>
      private void Form1_Load(System.Object eventSender, System.EventArgs eventArgs)
      {
          try
          {
              if (GXPing1.IsOpen)
              {
                  OnMediaStateChange(GuruxPing.GX_MEDIA_STATE_CHANGE.GX_MEDIA_STATE_CHANGE_OPEN);
              }
              else
              {
                  OnMediaStateChange(GuruxPing.GX_MEDIA_STATE_CHANGE.GX_MEDIA_STATE_CHANGE_CLOSE);
              }
          }
          catch (Exception Ex)
          {
              MessageBox.Show(Ex.Message);
          }				
      }
	
      /// <summary>
      /// Closes media, when the window is closed.
      /// </summary>
      /// <param name="eventSender"></param>
      /// <param name="eventArgs"></param>
      private void Form1_FormClosed(System.Object eventSender, System.Windows.Forms.FormClosedEventArgs eventArgs)
      {
          try
          {
              GXPing1.Close();		
          }
          catch (Exception Ex)
          {
              MessageBox.Show(Ex.Message);
          }			
      }

      /// <summary>
      /// To improve the performance of communication, the GXPing component can 
      /// send an error notification directly through its own thread. Windows, however, 
      /// does not allow all UI components to be used from another thread. 
      /// As the updated notifications cannot be shown automatically, the application 
      /// itself has to show them. This is done by using BeginInvoke function, as shown below.
      /// </summary>
      /// <param name="ErrorInfo"></param>
      private void OnError(string ErrorInfo)
      {
          try
          {
              MessageBox.Show(ErrorInfo);
          }
          catch (Exception Ex)
          {
              MessageBox.Show(Ex.Message);
          }
      }

      /// <summary>
      /// To improve the performance of communication, the GXPing component can 
      /// send an error notification directly through its own thread. 
      /// Windows, however, does not allow all UI components to be used from another thread. 
      /// As the updated notifications cannot be shown automatically, the application itself 
      /// has to show them. This is done by using BeginInvoke function, as shown below.
      /// </summary>
      /// <param name="eventSender"></param>
      /// <param name="eventArgs"></param>
      private void GXPing1_OnError(System.Object eventSender, AxGuruxPing.IGXPingEvents_OnErrorEvent eventArgs)
      {
          try
          {
              this.BeginInvoke(new GuruxPing.IGXPingEvents_OnErrorEventHandler(OnError), new object[] { eventArgs.errorInfo });
          }
          catch (Exception Ex)
          {
              MessageBox.Show(Ex.Message);
          }
      }        

      /// <summary>
      /// To improve the performance of communication, the GXPing component can 
      /// send a notification of a changed media state, directly through its own thread. 
      /// Windows, however, does not allow all UI components to be used from another thread. 
      /// As the updated notifications cannot be shown automatically, the application itself 
      /// has to show them. This is done by using BeginInvoke function, as shown below.
      /// </summary>
      /// <param name="State"></param>
      private void OnMediaStateChange(GuruxPing.GX_MEDIA_STATE_CHANGE State)
      {
        if ((State & GuruxPing.GX_MEDIA_STATE_CHANGE.GX_MEDIA_STATE_CHANGE_OPEN) != 0)
        {
          TimeOutTB.ReadOnly = CountTB.ReadOnly = HostName.ReadOnly = true;
        }
        else if ((State & GuruxPing.GX_MEDIA_STATE_CHANGE.GX_MEDIA_STATE_CHANGE_CLOSE) != 0)
        {
          TimeOutTB.ReadOnly = CountTB.ReadOnly = HostName.ReadOnly = false;
        }
      }

      /// <summary>
      /// To improve the performance of communication, the GXPing component can 
      /// send a notification of a changed media state, directly through its own thread. 
      /// Windows, however, does not allow all UI components to be used from another thread. 
      /// As the updated notifications cannot be shown automatically, the application itself 
      /// has to show them. This is done by using BeginInvoke function, as shown below.
      /// </summary>
      /// <param name="eventSender"></param>
      /// <param name="eventArgs"></param>
      private void GXPing1_OnMediaStateChange(System.Object eventSender, AxGuruxPing.IGXPingEvents_OnMediaStateChangeEvent eventArgs)
      {
        try
        {
          this.BeginInvoke(new GuruxPing.IGXPingEvents_OnMediaStateChangeEventHandler(OnMediaStateChange), new object[] { eventArgs.state });
        }
        catch (Exception Ex)
        {
          MessageBox.Show(Ex.Message);
        }
      }

      /// <summary>
      /// Ping selected host.
      /// </summary>
      /// <param name="eventSender"</param>
      /// <param name="eventArgs"</param>
      private void PingBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
      {
        try
        {
          LogTB.Text = "";
          GXPing1.HostName = HostName.Text;
          GXPing1.Timeout = int.Parse(TimeOutTB.Text);
          GXPing1.Count = int.Parse(CountTB.Text);
          GXPing1.Ping();
        }
        catch (Exception Ex)
        {
            MessageBox.Show(Ex.Message);
        }
      }

      /// <summary>
      /// To improve the performance of communication, the GXPing component can 
      /// send a notification of data received, directly through its own thread. 
      /// Windows, however, does not allow all UI components to be used from another thread. 
      /// As the updated notifications cannot be shown automatically, the application itself 
      /// has to show them. This is done by using BeginInvoke function, as shown below.
      /// </summary>
      private void OnPing(GuruxPing.GX_PING_STATE State, int SentCount, int LostCount, int LastTime, int AverageTime, int MinimumTime, int MaximumTime)
      {
        try
        {
          if (State == GuruxPing.GX_PING_STATE.GX_PING_STATE_OK)
          {
            LogTB.Text += LastTime.ToString() + "/" + AverageTime.ToString() + System.Environment.NewLine;
            MinTB.Text = MinimumTime.ToString();
            MaxTB.Text = MaximumTime.ToString();
            AverageTB.Text = AverageTime.ToString();
          }
        }
        catch (Exception Ex)
        {
          MessageBox.Show(Ex.Message);
        }
     }

      /// <summary>
      /// Asks UI to show received data.
      /// </summary>
      /// <param name="eventSender"></param>
      /// <param name="eventArgs"></param>
      private void GXPing1_OnPing(object sender, _IGXPingEvents_OnPingEvent e)
      {
        try
        {
          this.BeginInvoke(new GuruxPing._IGXPingEvents_OnPingEventHandler(OnPing), new object[] { e.state, e.sentCount, e.lostCount, e.lastTime, e.averageTime, e.minimumTime, e.maximumTime });
        }
        catch (Exception Ex)
        {
          MessageBox.Show(Ex.Message);
        }
      }
	
      /// <summary>
      /// Shows GXPing media properties.
      /// </summary>
      /// <param name="eventSender"></param>
      /// <param name="eventArgs"></param>
      private void PropertiesBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
      {
          try
          {
              GXPing1.Properties(this.Handle.ToInt32());
          }
          catch (Exception Ex)
          {
              MessageBox.Show(Ex.Message);
          }
      }
    }
}