public OverlayService(IStatisticProvider statisticProvider, ISensorService sensorService, IOverlayEntryProvider overlayEntryProvider, IAppConfiguration appConfiguration, ILogger <OverlayService> logger, IRecordManager recordManager, IRTSSService rTSSService, IOverlayEntryCore overlayEntryCore) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); _statisticProvider = statisticProvider; _overlayEntryProvider = overlayEntryProvider; _appConfiguration = appConfiguration; _logger = logger; _recordManager = recordManager; _sensorService = sensorService; _rTSSService = rTSSService; _overlayEntryCore = overlayEntryCore; _numberOfRuns = _appConfiguration.SelectedHistoryRuns; SecondMetric = _appConfiguration.RunHistorySecondMetric; ThirdMetric = _appConfiguration.RunHistoryThirdMetric; IsOverlayActiveStream = new BehaviorSubject <bool>(_appConfiguration.IsOverlayActive); _runHistoryOutlierFlags = Enumerable.Repeat(false, _numberOfRuns).ToArray(); _logger.LogDebug("{componentName} Ready", this.GetType().Name); Task.Run(async() => await InitializeOverlayEntryDict()) .ContinueWith(t => { IsOverlayActiveStream .AsObservable() .Select(isActive => { if (isActive) { _rTSSService.CheckRTSSRunning().Wait(); _rTSSService.OnOSDOn(); _rTSSService.ClearOSD(); return(_onDictionaryUpdated. SelectMany(_ => _overlayEntryProvider.GetOverlayEntries())); } else { _rTSSService.ReleaseOSD(); return(Observable.Empty <IOverlayEntry[]>()); } }) .Switch() .Subscribe(async entries => { _rTSSService.SetOverlayEntries(entries); await _rTSSService.CheckRTSSRunningAndRefresh(); }); }); _sensorService.SensorSnapshotStream .Sample(_sensorService.OsdUpdateStream.Select(timespan => Observable.Concat(Observable.Return(-1L), Observable.Interval(timespan))).Switch()) .Where((_, idx) => idx == 0 || IsOverlayActive) .SubscribeOn(Scheduler.Default) .Subscribe(sensorData => { UpdateOverlayEntries(sensorData.Item2); _onDictionaryUpdated.OnNext(_overlayEntryCore.OverlayEntryDict.Values.ToArray()); }); _runHistory = Enumerable.Repeat("N/A", _numberOfRuns).ToList(); _rTSSService.SetRunHistory(_runHistory.ToArray()); _rTSSService.SetRunHistoryAggregation(string.Empty); _rTSSService.SetRunHistoryOutlierFlags(_runHistoryOutlierFlags); _rTSSService.SetIsCaptureTimerActive(false); stopwatch.Stop(); _logger.LogInformation(GetType().Name + " {initializationTime}s initialization time", Math.Round(stopwatch.ElapsedMilliseconds * 1E-03, 1)); }