title: How to display the data read in DataReceived event handler of serialport
body: <p>I have the following code which needs the data to be read from port and then display in a textbox. I am using DataReceived event handler for this purpose but donot know how to display this data in textbox. From various sources i learnt that Invoke method should be used for this but donot know how to use it. Suggestions please...</p>
  
  <pre><code>    private void Form1_Load(object sender, EventArgs e)
      {
          //SerialPort mySerialPort = new SerialPort("COM3");
          mySerialPort.PortName = "COM3";
          mySerialPort.BaudRate = 9600;
          mySerialPort.Parity = Parity.None;
          mySerialPort.StopBits = StopBits.One;
          mySerialPort.DataBits = 8;
          mySerialPort.Handshake = Handshake.None;
          mySerialPort.DataReceived += new SerialDataReceivedEventHandler(mySerialPort_DataReceived);
          mySerialPort.Open();
      }
  
      private void mySerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
      {
          SerialPort sp = (SerialPort)sender;
          string s= sp.ReadExisting();
          // next i want to display the data in s in a textbox. textbox1.text=s gives a cross thread exception
      }
      private void button1_Click(object sender, EventArgs e)
      {
  
          mySerialPort.WriteLine("AT+CMGL=\"ALL\"");
  
      }
  </code></pre>