[英]Call SignalR Client method from normal C# class
I am trying to add SignalR in my MVC project. 我试图在我的MVC项目中添加SignalR 。 I need to call a SignalR client method from my class library.
我需要从我的类库中调用SignalR客户端方法。 I did below code
我做了下面的代码
public class CommomHubManager : ICommomHubManager
{
readonly IHubContext Context;
public CommomHubManager()
{
Context = Helpers.Providers.HubContextProvider<Hubs.Notifications>.HubContext;
}
public Task AddUserToGroup(string groupName)
{
return Task.Factory.StartNew(() => {
Context.Clients.All.addUserToGroup(groupName);
});
}
}
Its not working, but when i try to call an another Hub class method from WebApi its working just fine. 它不起作用,但是当我尝试从WebApi调用另一个Hub类方法时,它的工作正常。 I want to know that is it possible to call SignalR Client method from normal C# class?
我想知道是否可以从普通C#类调用SignalR Client方法?
How to use SignalR hub instance outside of the hubpipleline 如何在中心线之外使用SignalR集线器实例
var context = GlobalHost.ConnectionManager.GetHubContext<CommomHubManager>();
context.Clients.All.Send("Admin", "stop the chat");
You can find out more in the SignalR documentation . 您可以在SignalR文档中找到更多信息 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.