Pin the arduino to check connectivity c#

I was wondering if someone could tell me how to pin an arduino through c#, to check connectivity?
I established connection, by checking a serial port and opening it, but I want to be able to check the connectivity to the arduino, by making a pin to it, and if it is connected, it should return a message.
Can someone help me?
Thanks.

to pin an arduino through c#,

??
Do you mean ping?

If so then you have to have the arduino receive the message and return something.

http://arduino.cc/en/Serial/read

and

http://playground.arduino.cc/Main/InterfacingWithSoftware

This function scans your ports to find which is currently in use. It assumes the Arduino IDE is open and the board and port have been set, but the Serial monitor is NOT open when the C# function is used.

using System.IO.Ports;

   SerialPort currentPort;        // Global scope 

  private void SetComPort()                   // See which COM ports are available
  {
    try
    {
      string[] ports = SerialPort.GetPortNames();  // 
      foreach (string port in ports)
      {
        currentPort = new SerialPort(port, 9600);
        currentPort.PortName = port;
        serialPort1.PortName = port;
        txtPortName.Text = port;
        currentPort.Parity = Parity.None;
        currentPort.DataBits = 8;
        currentPort.StopBits =  (StopBits) 1;

        if (DetectArduino())
        {
          portFound = true;
          break;
        }
        else
        {
          portFound = false;
        }
      }
    }
    catch (Exception ex)
    {
      MessageBox.Show(ex.Message, "Error Reading Port");
    }
  }


 private bool DetectArduino()
  {
    try
    {
      //The below setting are for the Hello handshake
       
      byte[] buffer = new byte[5];
      buffer[0] = (byte) '[';

      int intReturnASCII = 0;
      char charReturnValue = (char)intReturnASCII;
      currentPort.Open();
      currentPort.Write(buffer, 0, 1);
      Thread.Sleep(1000);
      int count = currentPort.BytesToRead;
      string returnMessage = "";
      while (count > 0)
      {
        intReturnASCII = currentPort.ReadByte();
        returnMessage = returnMessage + Convert.ToChar(intReturnASCII);
        count--;
      }
      
      currentPort.Close();
      if (returnMessage.Contains("ACKNOWLEDGE"))
      {
        return true;
      }
      else
      {
        return false;
      }
    }
    catch (Exception e)
    {
      return false;
    }
  }

You can send whatever message you wish from the Arduino and check it once received.

It assumes the Arduino IDE is open and the board and port have been set

Why? That program is not talking to the IDE.

Sorry, I forgot the g in ping.
I took your advice and this is the code I currently have:
C#

                    SerialPort port = new SerialPort(cboPorts.Text
                    port.Open();                    
                    port.RtsEnable = true;
                    port.DtrEnable = true;
                    connect.Enabled = false;
                    MessageBox.Show("Port is open");
                    if (port.IsOpen)
                    {
                        port.Write(new byte[] { 1 }, 0, 1);
                        String msg = port.ReadLine();
                        if (msg == "connected")
                            st.Text = "The device is connected";
                    }

Arduino code:

       if(Serial.read()==(byte)1)
       Serial.write("connected");

The thing is that I never get the message "device is connected" on the label.
Can someone please help me?
Thanks.

How long does it take the Arduino to reset after you open the serial port? How long are you waiting for it to reset before you send the message? Before you read the response?

Have a look at how this Python demo deals with connecting to the Arduino. And IIRC this Python GUI demo checks the serial ports first.

...R