我在使用Hangfire的应用程序中有一些重复的后台作业:
public class NotificationWeeklyHub : Hub
{
public void SendNotificationWeekly()
{
/*Recurring Job
Clients.All.SendNotificationWeekly();
*/
// code....
}
}
因此,我想为我的用户发送通知,在这种情况下,我想在应用程序启动时呼叫我的集线器,那么我该如何以这种方式呼叫我的集线器?
PS:调用集线器的我的客户端代码:
<script src="~/Scripts/jquery.signalR-2.1.2.min.js"></script>
<script src="~/signalr/hubs"></script>
<script src="~/Scripts/toastr.min.js"></script>
<script>
var notifyWeekly = $.connection.notificationWeekly;
notifyWeekly.client.sendNotificationWeekly = function () {
toastr.success("Message");
};
$.connection.hub.start().done(function() {
notifyWeekly.server.sendNotificationWeekly();
});
</script>
我的目标是在特定时间发送通知(在我的情况下,使用Toastr库)。任何的想法?
提前致谢
可能会执行以下操作:
protected void Application_Start()
{
// get the hub from the globalHost
IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<NotificationWeeklyHub>();
// send the message to all clients, make sure that the method is camelCase.
hubContext.Clients.All.sendNotificationWeekly("your message");
}
编辑:
现在关于您的中心代码,看来您的方法只是调用客户端,并且由于您中心中的任何公共方法都可供客户端使用,因此您可以清除您的中心代码并将其更改为如下所示:
public class NotificationWeeklyHub : Hub
{
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句