title: C# - SerialDataReceivedEventHandler executing on second event (first event always skipped)
body: <p>I have barcode scanner that is using COM4 port.
  Every time I scan something, program will start to read barcodes after second scan.</p>
  <p>So, I build a project, try to scan and nothing happends. I try to scan again (in this running project) and it starts working perfectly.</p>
  <p>On the top of project I declare port as:</p>
  <pre><code>SerialPort port = new SerialPort();
  </code></pre>
  <p>I have a method that defines port:</p>
  <pre><code>public void ScannerPortSetup()
  {
          port.PortName = &quot;COM4&quot;;               
          port.BaudRate = 9600;
          port.Handshake = Handshake.None;
          port.Parity = Parity.None;
          port.DataBits = 8;
          port.StopBits = StopBits.One;
          port.DtrEnable = true;
          port.ReadTimeout = 200;
  
          try
          {
              port.Open();
              
              if (port.IsOpen == true)
              {
                  port.DataReceived += new SerialDataReceivedEventHandler(Recieve);
                  
               }
  
              else
              {
                  //print not opened
              }
          }
  
          catch (Exception e)
          {
              MessageBox.Show(&quot;Error on com4: &quot; + e);
          }
   }
  </code></pre>
  <p>Method that defines received action:</p>
  <pre><code>    private void Recieve(object sender, SerialDataReceivedEventArgs e)
      {
  
          String recieved_data = port.ReadExisting();
     
          this.Dispatcher.Invoke(() =&gt;
          {
              if (currentScreenName == ApplicationPages.SkladisteScreen.ToString())
              {
                  MessageBox.Show(&quot;scanned completed:  &quot; + recieved_data);
              }
             
  
          }); 
      }
  </code></pre>
  <p>Again, I do not know why it does not fire on first event, but from second it works perfectly.
  It does not matter if I placed i.e. MessageBox inside this.Dispatcher.Invoke() or just above in  Recieve method. Seems like Recieve is not fired first time.</p>
  <p>Any ideas?</p>