public async Task Pair(CancellationToken cancellationToken = default) { try { await Observable.Create <PropertyChanges>(async observer => { var action = new Action <PropertyChanges>(observer.OnNext); var propertySignal = await _device1.WatchPropertiesAsync(action); try { await _device1.PairAsync().ConfigureAwait(false); } catch { propertySignal.Dispose(); throw; } return(propertySignal); }) .Where(x => x.GetStruct <bool>(nameof(Device1Properties.Paired)).GetValueOrDefault(false)) .Take(1) .ToTask(cancellationToken) .ConfigureAwait(false); } catch (TaskCanceledException) { await _device1.CancelPairingAsync().ConfigureAwait(false); throw; } }