Files
ASPReactDemo/Api/SignalR/SignalRSendService.cs
Frederic Beckmann 9b45752d1a **Initialize React Vite project with basic setup**
Add initial project structure including React, Vite, TailwindCSS, and Syncfusion dependencies. Configure tooling with ESLint, TypeScript, and Tailwind plugins. Set up `.gitignore`, Syncfusion themes, and example components for demonstration purposes.
2025-02-07 23:21:46 +01:00

31 lines
1.1 KiB
C#

using Microsoft.AspNetCore.SignalR;
namespace Api.SignalR
{
public class SignalRSendService(IHubContext<WeatherUpdateHub> hubContext, ILogger<SignalRSendService> logger) : BackgroundService
{
#region Override ExecuteAsync
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
// For example, wait 10 seconds between messages.
await Task.Delay(TimeSpan.FromSeconds(2), stoppingToken);
// Log or do any work here.
logger.LogInformation("Background service sending message at: {Time}", DateTime.Now);
// Send a message to all connected clients.
await hubContext.Clients.User("user1234").SendAsync(
"ReceiveMessage", // This is the client method name.
"Background Service", // Example sender.
$"Hello from the background task at {DateTime.Now:F}", // The message.
stoppingToken);
}
}
#endregion
}
}