UWP and SerialCommunication: await DeviceInformation.FindAllAsync(aqs) won't finish...

Hello!

I am writing(for work) a library for multiple platforms: .NET Framework, .NET Core and Xamarin.Forms(UWP/Android/iOS) to connect a serialdevice.
To get an overall compatibility i created an Interface that is similar to the methods of System.IO.Ports.SerialPort. So i have now an adapterclass which is specific for every platform. System.IO.Ports.SerialPort used for .NET Core and Windows.Devices.SerialCommunication used for UWP...
.NET Framework and .NET Core are running fine. UWP is a little bit strange:
The folowing Code is running fine with an (UWP)Console App(Console App (Universal) Project Templates) with a fresh UWP blank App or a Xamarin.Forms App for UWP it is hanging in DeviceInformation.FindAllAsync(aqs).
Also a purpose of the adapterclass is to get rid of the annoying (for me) async stuff. (the lib is not running on the ui thread and it is not time critical)

        public string[] GetPortNames()
        {
            Task<List<string>> portNamesList = GetPortNamesAsync();
            return portNamesList.Result.ToArray();
        }
        private static async Task<List<string>> GetPortNamesAsync()
        {
            string aqs = SerialDevice.GetDeviceSelector();
            var deviceCollection = await DeviceInformation.FindAllAsync(aqs); <-- here it hangs
            List<string> portNamesList = new List<string>();
            foreach (var item in deviceCollection)
            {
                var sd = await SerialDevice.FromIdAsync(item.Id);
                if (sd != null)
                {
                    var portName = sd.PortName;
                    if (portName != null) portNamesList.Add(portName);
                    sd.Dispose();
                }
            }
            return portNamesList;
        }

Thanks in advance! :)
MadMe86

Sign In or Register to comment.