using Dlhis.Message.Services; using Microsoft.AspNetCore.SignalR; namespace Dlhis.Message { public class TestBackgroundService : BackgroundService, ISingletonDependency { private readonly IHubContext _hubContext; public TestBackgroundService(IHubContext hubContext) { _hubContext = hubContext; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { await _hubContext.Clients.All.Raise(new Dictionary { ["name"] = "ligy" }); await Task.Delay(1000 * 10); } } } }