123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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;
- }
- /// <summary>
- /// This method is called when the <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> starts. The implementation should return a task that represents
- /// the lifetime of the long running operation(s) being performed.
- /// </summary>
- /// <param name="stoppingToken">Triggered when <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" /> is called.</param>
- /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.</returns>
- /// <remarks>See <see href="https://docs.microsoft.com/dotnet/core/extensions/workers">Worker Services in .NET</see> for implementation guidelines.</remarks>
- protected override async Task ExecuteAsync(CancellationToken stoppingToken)
- {
- using var scope = _serviceScopeFactory.CreateScope();
- var realtimeService = scope.ServiceProvider.GetRequiredService<IRealtimeService>();
- while (!stoppingToken.IsCancellationRequested)
- {
- //todo
- var data = new {
- Name = "John",
- Age = 20,
- };
- await realtimeService.BsDataShowChangedAsync(data, stoppingToken);
- await Task.Delay(30000, stoppingToken);
- }
- }
- }
- }
|