internal void DoTryGetDesk(CancellationToken token) { while (Desk == null && !token.IsCancellationRequested) { _logger.Information("Trying to find desk..."); DeskDetectedEvent.WaitOne(TimeSpan.FromSeconds(1)); } }
internal void OnDeskDetected(IDesk desk) { _logger.Information($"Detected desk {desk.Name} with " + $"Bluetooth address {desk.BluetoothAddress}"); _detector.Stop( ); Desk = desk; DeskDetectedEvent.Set( ); }
/// <inheritdoc /> public async Task <(bool, IDesk)> TryGetDesk(CancellationToken token) { Desk?.Dispose( ); Desk = null; try { _detector.Start( ); await _taskRunner.Run(() => DoTryGetDesk ( token ), token); if (token.IsCancellationRequested) { return(false, null); } return(Desk == null ? (false, null) : (true, Desk)); } catch (Exception e) { if (e.IsBluetoothDisabledException( )) { e.LogBluetoothStatusException(_logger); } else { _logger.Error(e, "Failed to detect desk"); } return(false, null); } finally { _detector.Stop( ); DeskDetectedEvent.Reset( ); } }