简体   繁体   English

从控制台应用程序调用signalR集线器方法

[英]Calling signalR hub methods from console application

I have a requirement like, when my database get updated with new data, I want to trigger the refreshAllClient method on signalR hub. 我有一个要求,例如,当我的数据库被新数据更新时,我想触发signalR集线器上的refreshAllClient方法。 This method call every client connected to my application and trigger refresh method on client. 此方法调用连接到我的应用程序的每个客户端,并在客户端上触发刷新方法。 So that all users will have live record. 这样所有用户都会有实时记录。 Actually the data are coming from different sources(multiple clients), when the data are ready, console application will start to move data into database. 实际上,数据来自不同的来源(多个客户端),当数据准备就绪时,控制台应用程序将开始将数据移入数据库。 Once date get updated, console application need to trigger method on signalR. 日期更新后,控制台应用程序需要在signalR上触发方法。 How do I trigger signalR hub from console application? 如何从控制台应用程序触发signalR集线器?

the key is this kind of thing 关键是这种事情

  var ctx = GlobalHost.ConnectionManager.GetHubContext<yourhub>();
  ctx.Clients.Client(connectionId).<your method>  

The point is you now have a hub context that allows sending to a client a group or all 关键是您现在有了一个中心上下文,该上下文允许将一组或全部发送给客户端

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM