in BluetoothLEExplorer/BluetoothLEExplorer/Models/GattSampleContext.cs [785:833]
private async Task AddDeviceToList(DeviceInformation deviceInfo)
{
ObservableBluetoothLEDevice dev = new ObservableBluetoothLEDevice(deviceInfo);
// Let's make it connectable by default, we have error handles in case it doesn't work
bool shouldDisplay =
((dev.DeviceInfo.Properties.Keys.Contains("System.Devices.Aep.Bluetooth.Le.IsConnectable") &&
(bool)dev.DeviceInfo.Properties["System.Devices.Aep.Bluetooth.Le.IsConnectable"])) ||
((dev.DeviceInfo.Properties.Keys.Contains("System.Devices.Aep.IsConnected") &&
(bool)dev.DeviceInfo.Properties["System.Devices.Aep.IsConnected"])) ||
((dev.DeviceInfo.Properties.Keys.Contains("System.Devices.Aep.IsPaired") &&
(bool)dev.DeviceInfo.Properties["System.Devices.Aep.IsPaired"]));
if (shouldDisplay)
{
// Need to lock as another DeviceWatcher might be modifying BluetoothLEDevices
try
{
await BluetoothLEDevicesLock.WaitAsync();
if (!BluetoothLEDevices.Contains(dev))
{
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
Windows.UI.Core.CoreDispatcherPriority.Normal,
() =>
{
BluetoothLEDevices.Add(dev);
});
}
}
finally
{
BluetoothLEDevicesLock.Release();
}
}
else
{
try
{
await BluetoothLEDevicesLock.WaitAsync();
unusedDevices.Add(deviceInfo);
dev.Dispose();
}
finally
{
BluetoothLEDevicesLock.Release();
}
}
}