Trying to get a list of COM ports in the UWP . I write the list of ports to the variable dis , but it immediately goes to the next line, although there is await . How to make await wait for all ports to return correctly?

 try { string devSel = SerialDevice.GetDeviceSelector(); var dis = await DeviceInformation.FindAllAsync(devSel); for (int i = 0; i < dis.Count; i++) { lst.Add(dis[i]); } serialPort = await SerialDevice.FromIdAsync(lst[0].Id); } catch (Exception ex) { } 
  • To wait, it must be used. Only if immediately after the request put some use of serialPort , then you actually have a synchronous code. - Monk
  • Well, how to wait for it? I basically do not care - synchronous code or asynchronous. - Radzhab
  • I did not come across this interface, but in api there are GetResults , plus typically await asynchronous before using the variable in which it is clogged, i.e. before any operation with your serialPort variable. - Monk

0