title: UWP SerialDevice works only if I read it's properties
body: <p>So, I have some code for setting up my serial port in UWP (which is used with an USB-to-Serial adapter):</p>
  
  <pre><code>public async Task Init() 
  {
          string qFilter = SerialDevice.GetDeviceSelector("COM5"); 
          DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(qFilter);
          deviceId = devices.First().Id;
          var serialPort = await SerialDevice.FromIdAsync(deviceId);
  
          serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
          serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
          serialPort.BaudRate = 4800;
          serialPort.Parity = SerialParity.None;
          serialPort.StopBits = SerialStopBitCount.One;
          serialPort.DataBits = 8;
          serialPort.Handshake = SerialHandshake.None;
  }
  </code></pre>
  
  <p>now, somewhere later in the code, I read a stream from the SerialDevice:</p>
  
  <pre><code>public async Task&lt;string&gt; ReadValueFromSerial()
  {
          var dataReaderObject = new DataReader(serialPort.InputStream);
          uint ReadBufferLength = 1024;
          dataReaderObject.InputStreamOptions = InputStreamOptions.Partial;
  
          CancellationTokenSource cts = new CancellationTokenSource();
          //set timeout here.
          cts.CancelAfter(10000);
          var bytesRead = await dataReaderObject.LoadAsync(ReadBufferLength).AsTask(cts.Token);
          (...)
  }
  </code></pre>
  
  <p>no above code hangs on the last line, altough I know, that the serial device is sending bytes to the serial port.</p>
  
  <p>Funny thing is, that it works, when I put a breakpoint on the set-up part (the first snippet). But without a breakpoint and stepping through it, it just hangs, or times out.</p>
  
  <p>By trials and errors I found out, that reading the serial device properties which I set in the set-up code, makes it magically work.</p>
  
  <p>So after the code in the first snippet, I have added:</p>
  
  <pre><code>public async Task Init() 
  {
           (...)
           var s1 = " " + serialPort.BaudRate;
           var s2 = " " + serialPort.DataBits;
           var s3 = " " + serialPort.Parity.ToString();
  }
  </code></pre>
  
  <p>And now the <code>var bytesRead = await dataReaderObject.LoadAsync(ReadBufferLength).AsTask(cts.Token);</code> doesn't hang anymore and the bytes are loaded. It works, which is great, but why?</p>