private void ScanToggleAsync() { if (this.IsScanning) { this.IsScanning = false; this._scan?.Dispose(); } else { this.Peripherals.Clear(); Debug.WriteLine("View" + Thread.CurrentThread.ManagedThreadId); this._scan = _centralManager .Scan() .Buffer(TimeSpan.FromSeconds(1)) .Synchronize() .ObserveOn(XamarinDispatcherScheduler.Current) .Subscribe( results => { //Debug.WriteLine("within: " + Thread.CurrentThread.ManagedThreadId); var list = new List <PeripheralItemViewModel>(); foreach (var result in results) { var peripheral = this.Peripherals.FirstOrDefault(x => x.Equals(result.Peripheral)); if (peripheral == null) { peripheral = list.FirstOrDefault(x => x.Equals(result.Peripheral)); } if (peripheral != null) { peripheral.Update(result); } else { peripheral = new PeripheralItemViewModel(result.Peripheral); peripheral.Update(result); list.Add(peripheral); } } foreach (var per in list) { this.Peripherals.Add(per); } RaisePropertyChanged(nameof(Peripherals)); }, ex => Console.WriteLine("ERROR: " + ex.ToString()) ) .DisposeWith(this.DeactivateWith); this.IsScanning = true; } RaisePropertyChanged(nameof(Peripherals)); RaisePropertyChanged(nameof(IsScanning)); }
private async void SelectPeripheral(PeripheralItemViewModel item) { var p = new NavigationParameters(); p.Add("Peripheral", item.Peripheral); var result = await _navigator.NavigateAsync("Peripheral", p); if (!result.Success) { Console.WriteLine("[NAV FAIL] " + result.Exception); } }