How to use SignalR hub instance outside of the hubpipleline

前端 未结 2 1897
天命终不由人
天命终不由人 2020-12-02 11:49

I am using SignalR to broadcast messages to all my clients. I need to trigger the broadcasting outside of my hub class i.e. something like below:

var broadcast

2条回答
  •  醉梦人生
    2020-12-02 12:30

    You need to use GetHubContext:

    var context = GlobalHost.ConnectionManager.GetHubContext();
    context.Clients.All.Send("Admin", "stop the chat");
    

    This is described in more detail at http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-server#callfromoutsidehub.

提交回复
热议问题