title: Serial Port.Datareceived is not firing (.net 4.5)
body: <p>I am using .net 4.5 and since i got aware about some internet discussion about .net having wrong code implementation to rad serial data, i went with the code below.</p>
  
  <p>The problems is however even despite i can see i create a COM port connection (to the right com port number), its never firing on data received. 
  The data receiving is based upon a simple Arduino app, (Arduino monitor does show data gets send over serial), but .net never seams to fire upon serial events.</p>
  
  <p>I've put breakpoints on eventread, it never gets hit</p>
  
  <p>i've looked at other discussions here like <a href="https://stackoverflow.com/questions/2281618/net-serialport-datareceived-event-not-firing">.NET SerialPort DataReceived event not firing</a>  but so far they don't resolve the issue i have. I tried various combination of serial line setups, and believe the below ones are correct.
  as for Arduino part the line is setup as:</p>
  
  <pre><code>Serial.begin(9600);
  </code></pre>
  
  <p>I call my class like : `InfraredSensor mySens = new InfraredSensor("COM4",9600);' </p>
  
  <pre><code>class InfraredSensor
  {
      private string Eventlogapp = "IRlogging"; 
      private SerialPort Port;
      public InfraredSensor(string COMport, int baudrate) //constructor
      {
          if (applicationlog != "") this.EventlogSapec = applicationlog;
          WriteEventLog(EventlogSapec, EventSource, "Initializing-IR:" + COMport, info, EventIRStarted);
  
          // I found that the .net standard implementation for com port reading is not OK (.net doesnt follow win32 api).
          // There are numerous readings about it, but a good way to read seams to be to use Serial BaseStream.ReadAsync
          // code below is based upon : http://www.c-sharpcorner.com/code/2880/serial-port-with-efficient-data-reading-in-c-sharp.aspx
  
          this.comport = COMport;
          SerialPort Port = new SerialPort(comport);
  
          Port.BaudRate = baudrate;
          Port.DataBits = 8;
          Port.Parity = Parity.None;
          Port.StopBits = StopBits.One;
          Port.Handshake = Handshake.None;
  
          Port.NewLine = Environment.NewLine;
          Port.ReceivedBytesThreshold = 2; // + linefeed 
          Port.DataReceived += ReadEvent;
          Port.Open();
          Port.DtrEnable = true;
         // i've tested from here i do have an open connection
         // its just dat ReadEvent never fires...
      }
  
  
        private void ReadEvent(object sender, SerialDataReceivedEventArgs e)
      {
          byte[] buffer = new byte[2];//todo i only send "A" or "B", for the debug moment 
          Action kickoffRead = null;
  
          kickoffRead = (Action)(() =&gt; Port.BaseStream.BeginRead(buffer, 0, buffer.Length, delegate (IAsyncResult ar)
          {
              try
              {
                  int count = Port.BaseStream.EndRead(ar);
                  byte[] dst = new byte[count];
                  Buffer.BlockCopy(buffer, 0, dst, 0, count);
                  RaiseAppSerialDataEvent(dst);
              }
              catch (Exception ex)
              {
                  WriteEventLog(Eventlogapp, "IR", "Failure-IR:" + ex.Message, info, 204);
              }
              kickoffRead();
          }, null)); kickoffRead();
      }
  
      private void RaiseAppSerialDataEvent(byte[] Data)
      {
      // code never gets to here
          string msg = Encoding.Default.GetString(Data);
      int breakpointhere = 0;
  
          if (msg.Contains('A')) WriteEventLog(Eventlogapp, "IR", "Sensor A", info, 213);
  
          if (msg.Contains('B')) WriteEventLog(Eventlogapp, "IR", "Sensor B", info, 214);
  
  
      }
  }
  </code></pre>
  
  <p>I ran out of ideas (and hair as its driving me nuts) what could cause this behaviour ?</p>