using System; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using OpenCvSharp; using Squirrowse.Client.Service; namespace Squirrowse.Client { public class Worker : BackgroundService { private readonly ILogger logger; private readonly IStreamService streamService; private readonly ICameraService camera; public Worker(ILogger logger, IStreamService streamService, ICameraService camera) { this.logger = logger; this.streamService = streamService; this.camera = camera; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); await streamService.SendStreamAsync(camera.GetFramesAsyncEnumerator()); // await Task.Delay(50, stoppingToken); } } } }