private async void comPortInput_Click(object sender, RoutedEventArgs e)        {            var selection = ConnectDevices.SelectedItems;            if (selection.Count <= 0)            {                status.Text = "Select a device and connect";                return;            }            DeviceInformation entry = (DeviceInformation)selection[0];            try            {                serialPort = await SerialDevice.FromIdAsync(entry.Id);                if (serialPort == null) return;                // Disable the 'Connect' button                comPortInput.IsEnabled = false;                // I know this two lines make a difference in reading the data from Arduino, but still, even if                // I've put ten seconds for writing and reading I think the result time would sometimes be                // more than it                serialPort.WriteTimeout = TimeSpan.FromMilliseconds(10);                serialPort.ReadTimeout = TimeSpan.FromMilliseconds(960);                                serialPort.BaudRate = 9600;                serialPort.Parity = SerialParity.None;                serialPort.StopBits = SerialStopBitCount.One;                serialPort.DataBits = 8;                serialPort.Handshake = SerialHandshake.None;                // Display configured settings                status.Text = "Serial port configured successfully: ";                status.Text += serialPort.BaudRate + "-";                status.Text += serialPort.DataBits + "-";                status.Text += serialPort.Parity.ToString() + "-";                status.Text += serialPort.StopBits;                // Set the RcvdText field to invoke the TextChanged callback                // The callback launches an async Read task to wait for data                //rcvdText.Text = "Waiting for data...";                // Create cancellation token object to close I/O operations when closing the device                ReadCancellationTokenSource = new CancellationTokenSource();                // Enable 'WRITE' button to allow sending data                sendTextButton.IsEnabled = true;                [b]Listen();[/b]            }            catch (Exception ex)            {                status.Text = ex.Message;                comPortInput.IsEnabled = true;                sendTextButton.IsEnabled = false;            }        }        private async void Listen()        {            try            {                if (serialPort != null)                {                    dataReaderObject = new DataReader(serialPort.InputStream);                    // keep reading the serial input                    while (true)                    {                        await ReadAsync(ReadCancellationTokenSource.Token);                    }                }            }            catch (TaskCanceledException tce)            {                status.Text = "Reading task was cancelled, closing device and cleaning up";                CloseDevice();            }            catch (Exception ex)            {                status.Text = ex.Message;            }            finally            {                // Cleanup once complete                if (dataReaderObject != null)                {                    dataReaderObject.DetachStream();                    dataReaderObject = null;                }            }        }        private async Task ReadAsync(CancellationToken cancellationToken)        {            Task loadAsyncTask;            uint ReadBufferLength = 1024;            string response = null;            // If task cancellation was requested, comply            cancellationToken.ThrowIfCancellationRequested();            // Also tried the three different InputStreamOptions and didn't noticed nothing better            dataReaderObject.InputStreamOptions = InputStreamOptions.Partial;            using (var childCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))            {                // Create a task object to wait for data on the serialPort.InputStream                loadAsyncTask = dataReaderObject.LoadAsync(ReadBufferLength).AsTask();                // Launch the task and wait                UInt32 bytesRead = await loadAsyncTask;                // If the message is exacly the size I'm sending it means it is a good message                if (bytesRead == 5)                {                    response = dataReaderObject.ReadString(bytesRead);                    rcvdText.Text = response;                    go = true;                    status.Text = "Good Message!";                }                else // It is a partial message which I can concatenate adapting the code to it. But still, this concatenation, sometimes, takes long to get the second part of the message.                {                    go = true;                    status.Text = "Bad Message!";                }            }        }        private async void sendTextButton_Click(object sender, RoutedEventArgs e)        {            try            {                if (!go)                    return;                go = false;                if (serialPort != null)                {                    // Create the DataWriter object and attach to OutputStream                    dataWriteObject = new DataWriter(serialPort.OutputStream);                    //Launch the WriteAsync task to perform the write                    await WriteAsync();                }                else                {                    status.Text = "Select a device and connect";                }            }            catch (Exception ex)            {                status.Text = "sendTextButton_Click: " + ex.Message;            }            finally            {                // Cleanup once complete                if (dataWriteObject != null)                {                    dataWriteObject.DetachStream();                    dataWriteObject = null;                }            }        }        private async Task WriteAsync()        {            Task storeAsyncTask;            if (sendText.Text.Length != 0)            {                rcvdText.Text = "";                // Load the text from the sendText input text box to the dataWriter object                dataWriteObject.WriteString(sendText.Text);                // Launch an async task to complete the write operation                storeAsyncTask = dataWriteObject.StoreAsync().AsTask();                UInt32 bytesWritten = await storeAsyncTask;                if (bytesWritten > 0)                {                    status.Text = sendText.Text + ", ";                    status.Text += "bytes written successfully!";                }            }            else            {                status.Text = "Enter the text you want to write and then click on 'WRITE'";            }        }