0

I have a WebApi2 controller method that starts a long-running background process:

public IHttpActionResult LongProcess()
{
    HostingEnvironment.QueueBackgroundWorkItem(ct =>
    {
        myService.RunLongProcess(ct);
    });

    return Ok();
}

The RunLongProcess is a method within a separate Services assembly. I'm also using SignalR in my project but currently for other purposes. SignalRis only located in the main WebApi project

How can I use SignalRto push notifications back to the client from the service method?

Should I start the hub in the action (within the HostingEnvironment block and then pass a callback delegate to the method, which in turn will use SignalR to push notifications?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • You can just call hub methods from your background process, as shown in [this answer](https://stackoverflow.com/questions/17395201/call-a-hub-method-from-a-controllers-action). – mason Dec 13 '18 at 14:27
  • @mason Yes I know I need to call hub methods from within the controller action. But the actual work is done in the server method and I need to pass info back to the action. – Ivan-Mark Debono Dec 13 '18 at 14:45
  • No, I'm not saying to do to the work from the controller action. I'm saying to do the work from the background method. The code to do it from a controller action vs a server method is the same either way, which is why I linked to that answer. – mason Dec 13 '18 at 14:49
  • https://learn.microsoft.com/en-us/aspnet/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr – K Scandrett Jun 29 '19 at 22:33

0 Answers0