private void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (_tlv == null) { _tlv = new Tlv(); } var bytesToRead = _serialPort.BytesToRead; while (bytesToRead-- > 0) { if (_tlv.ReadByte(_serialPort.ReadByte())) { var tlv = _tlv; _tlv = new Tlv(); Invoke((MethodInvoker) delegate { // Running on the UI thread OnTlvReceived(tlv); }); } } }