Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

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


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);
            return portNamesList;

Thanks in advance! :)


  • SListSList USMember ✭✭

    Hi, did you ever solve this problem? I have just implemented FindAllAsync for SerialDevices in an UWP app, and it is working OK so far, on my computer(!).

Sign In or Register to comment.