private async void DeviceWatcher_Added(object sender, object deviceInfo) { // We must update the collection on the UI thread because the collection is databound to a UI element. await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { lock (this) { CSLibrary.DeviceFinder.DeviceFinderArgs dfa = (CSLibrary.DeviceFinder.DeviceFinderArgs)deviceInfo; CSLibrary.DeviceFinder.DeviceInfomation di = (CSLibrary.DeviceFinder.DeviceInfomation)dfa.Found; DeviceInformation ndi = (DeviceInformation)di.nativeDeviceInformation; Debug.WriteLine(String.Format("Added {0}{1}", di.ID, di.deviceName)); // Make sure device isn't already present in the list. if (FindBluetoothLEDeviceDisplay(ndi.Id) == null) { if (di.deviceName != string.Empty) { // If device has a friendly name display it immediately. KnownDevices.Add(new BluetoothLEDeviceDisplay(ndi)); } else { // Add it to a list in case the name gets updated later. UnknownDevices.Add(ndi); } } } }); }
private async void DeviceWatcher_Added(object sender, object deviceInfo) { // We must update the collection on the UI thread because the collection is databound to a UI element. //await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { lock (this) { CSLibrary.DeviceFinder.DeviceFinderArgs dfa = (CSLibrary.DeviceFinder.DeviceFinderArgs)deviceInfo; CSLibrary.DeviceFinder.DeviceInfomation di = (CSLibrary.DeviceFinder.DeviceInfomation)dfa.Found; //DeviceInformation ndi = (DeviceInformation)di.nativeDeviceInformation; string a = String.Format("Added {0} {1}", di.ID, di.deviceName); Debug.WriteLine(a); listView1.Items.Add(di.deviceName); } } }