Beispiel #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await Initialize();

            Log.Debug("Starting main Color Service loop...");
            await Task.Run(async() => {
                var cTask     = ControlService.Execute(stoppingToken);
                var loopWatch = new Stopwatch();
                loopWatch.Start();
                while (!stoppingToken.IsCancellationRequested)
                {
                    await CheckAutoDisable().ConfigureAwait(false);

                    // Save a frame every 5 seconds
                    if (loopWatch.Elapsed >= TimeSpan.FromSeconds(5))
                    {
                        FrameSaveEvent.Invoke();
                        loopWatch.Restart();
                    }

                    if (!ColorsUpdated)
                    {
                        continue;
                    }

                    if (!_demoComplete || _stream == null)
                    {
                        return;
                    }

                    Counter.Tick("");
                    ColorsUpdated = false;
                    await SendColors(LedColors, SectorColors);
                }

                if (cTask.IsCompleted)
                {
                    Log.Debug("CTask canceled.");
                }

                loopWatch.Stop();
                Log.Information("Send loop canceled.");

                _streamTask?.Dispose();
                DataUtil.Dispose();
            }, CancellationToken.None);
        }