L
L
Lev Fedorov2020-04-27 11:42:59
ASP.NET
Lev Fedorov, 2020-04-27 11:42:59

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

1 answer(s)
I
Ilya, 2020-04-27
@blvckheart0

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 question

Ask a Question

731 491 924 answers to any question