Squirrowse/Squirrowse.Client/Worker.cs

38 lines
1.1 KiB
C#
Raw Normal View History

2019-10-31 13:08:42 +01:00
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
2019-11-05 10:30:31 +01:00
using OpenCvSharp;
2019-11-01 19:04:24 +01:00
using Squirrowse.Client.Service;
2019-10-31 13:08:42 +01:00
namespace Squirrowse.Client
{
public class Worker : BackgroundService
{
2019-11-04 14:28:45 +01:00
private readonly ILogger<Worker> logger;
private readonly IStreamService streamService;
private readonly ICameraService camera;
2019-10-31 13:08:42 +01:00
2019-11-04 14:28:45 +01:00
public Worker(ILogger<Worker> logger, IStreamService streamService, ICameraService camera)
2019-10-31 13:08:42 +01:00
{
2019-11-04 14:28:45 +01:00
this.logger = logger;
this.streamService = streamService;
this.camera = camera;
2019-10-31 13:08:42 +01:00
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
2019-11-05 10:30:31 +01:00
while (!stoppingToken.IsCancellationRequested)
{
2019-11-04 14:28:45 +01:00
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
2019-11-04 09:29:37 +01:00
2019-11-04 14:28:45 +01:00
await streamService.SendStreamAsync(camera.GetFramesAsyncEnumerator());
2019-11-05 10:30:31 +01:00
// await Task.Delay(50, stoppingToken);
}
2019-10-31 13:08:42 +01:00
}
}
2019-11-04 09:29:37 +01:00
}