Answer the question
In order to leave comments, you need to log in
How to call a SignalR hub method from a Quartz task?
There is a task in Quartz that processes data on a timer and I need that, under a certain condition, I can call the SignalR hub method directly from the task, which would send data to clients
Answer the question
In order to leave comments, you need to log in
Make a wrapper in the form of HostedService over the scheduler (take the example that allows you to receive services from the ServiceProvider)
https://docs.microsoft.com/en-us/aspnet/core/funda...
When the trigger fires, get the HubContext from the ServiceProvider for hub and send
https://docs.microsoft.com/en-us/aspnet/core/signa...
using (var scope = Services.CreateScope())
{
var hc = scope.ServiceProvider.GetRequiredService<HubContext<MyHub>>();
await hc.Clients.All.SendAsync("Notify", "Wub-laba-dub-da");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question