/// <summary> /// 删除不在范围内的蓝牙设备 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void LeDeviceFinder_Removed(DeviceWatcher sender, DeviceInformationUpdate args) { ThreadPool.QueueUserWorkItem(delegate { SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Application.Current.Dispatcher)); SynchronizationContext.Current.Post(pl => { LEDevices.Remove(new BluetoothLEDeviceModel(args.Id)); }, null); }); }
/// <summary> /// 添加在范围内的蓝牙设备 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void LeDeviceFinder_Added(DeviceWatcher sender, DeviceInformation args) { ThreadPool.QueueUserWorkItem(delegate { SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher)); SynchronizationContext.Current.Post(pl => { if (args.Name != "") { LEDevices.Add(new BluetoothLEDeviceModel(args)); } }, null); }); }