public void Start() { if (_watcher == null) { var watcher = new BluetoothLEAdvertisementWatcher() { ScanningMode = BluetoothLEScanningMode.Active }; watcher.SignalStrengthFilter = new BluetoothSignalStrengthFilter() { SamplingInterval = TimeSpan.Zero }; GlobalCounters.IncrementWatchersCreated(); watcher.Received += WatcherReceived; watcher.Stopped += WatcherStopped; _watcher = watcher; Log("Watcher created, has status " + _watcher.Status); } _watcher.Start(); IsStopped.Reset(); GlobalCounters.IncrementWatchersStarted(); Console.WriteLine("Watcher started, has status " + _watcher.Status); }
public void Start() { if (_watcher != null) { throw new Exception("Should only be started once"); } var watcher = new BluetoothLEAdvertisementWatcher() { ScanningMode = BluetoothLEScanningMode.Active }; watcher.SignalStrengthFilter = new BluetoothSignalStrengthFilter() { SamplingInterval = TimeSpan.Zero }; GlobalCounters.IncrementWatchersCreated(); var received = new Subject <Tuple <BluetoothLEAdvertisementReceivedEventArgs, BluetoothError?> >(); watcher.Received += (sender, args) => received.OnNext(new Tuple <BluetoothLEAdvertisementReceivedEventArgs, BluetoothError?>(args, null)); watcher.Stopped += (sender, args) => received.OnNext(new Tuple <BluetoothLEAdvertisementReceivedEventArgs, BluetoothError?>(null, args.Error)); watcher.Start(); _watcher = watcher; }