using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Hotline.Realtimes; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace Hotline.Application.Bigscreen { public class BigscreenDataShowRefreshService : BackgroundService { private readonly IServiceScopeFactory _serviceScopeFactory; public BigscreenDataShowRefreshService(IServiceScopeFactory serviceScopeFactory) { _serviceScopeFactory = serviceScopeFactory; } /// /// This method is called when the starts. The implementation should return a task that represents /// the lifetime of the long running operation(s) being performed. /// /// Triggered when is called. /// A that represents the long running operations. /// See Worker Services in .NET for implementation guidelines. protected override async Task ExecuteAsync(CancellationToken stoppingToken) { using var scope = _serviceScopeFactory.CreateScope(); var realtimeService = scope.ServiceProvider.GetRequiredService(); while (!stoppingToken.IsCancellationRequested) { //todo var data = new { Name = "John", Age = 20, }; await realtimeService.BsDataShowChangedAsync(data, stoppingToken); await Task.Delay(30000, stoppingToken); } } } }