title: C# read Data from 2 RS232(COM-Ports) independent
body: <p>Is there any possibility to read Data from 2 RS232 Ports parallel?</p>
  
  <p>It seems, that when i have 2 DataReceived-Events there are blocking each other.
  I have also tried to set the SerialPort.ReceivedBytesThreshold to a value of 50/100</p>
  
  <pre><code>class DataCollector
  {
  
      private SerialPort _serialPort;
      List&lt;String&gt; Data;
      private bool _finished = false;
      private bool _handshake = true;
  
      public DataCollector(SerialPort serialPort, bool handshake=true)
      {
          Data = new List&lt;String&gt;();
          _serialPort = serialPort;
  
          _serialPort.DataReceived += SerialPortDataReceived;
          _handshake = handshake;
          if (_serialPort.IsOpen)
          {
              _serialPort.DiscardInBuffer();
          }
      }
  
      ~DataCollector()
      {
          if (_serialPort.IsOpen)
          {
              _serialPort.DiscardInBuffer();
          }
          Data.Clear();
      }
  
      private void SerialPortDataReceived(object sender, SerialDataReceivedEventArgs e)
      {
          if (_handshake == false)
          {
  
              String str =_serialPort.ReadLine();
              str.Insert(str.Length, "\n");
  
              Data.Add(str);
  
  
              if (Data.Count == 48)
              {
                 _finished = true;
              }
          }
          else
          {
              Char readedByte = (char)_serialPort.ReadByte();
              if ((readedByte != (char)5) &amp;&amp; Data.Count == 0)
              {
  
                  return;
              }
              if (readedByte.CompareTo((char)2) == 0)
              {
                  readLine();
                  sendAck();
              }
              else if (readedByte.CompareTo((char)5) == 0)
              {
  
                  Data.Add(((char)5).ToString());
                  sendAck();
              }
              else if (readedByte == (char)4)
              {
                  _finished = true;
              }
          }
  
          private void sendAck()
          {
              if (_serialPort.IsOpen )
              {
                  Byte[] bytes = {6};
                  _serialPort.Write(bytes,0,1);
              }
          }
          private void readLine(){
              String str = _serialPort.ReadLine();
              Data.Add(str);
          }
      }
  </code></pre>
  
  <p>There are 2 defined in the Main:</p>
  
  <pre><code>_inputCollector = new DataCollector(_RS232Input);
  
  _inputSecondCollector = new DataCollector(_RS232SecondInput, false);
  </code></pre>