How to use SignalR for autorefresh like data

若如初见. 提交于 2019-12-25 03:42:30

问题


I've been looking into using SignalR for a while now, and I think I have a good candidate for it.

I have a page which allows users of the system to leave Comments, and at the moment it uses JQuery to periodically refresh the list of comments. I think SignalR would replace this nicely, i.e. if there were two users looking at the list and one wrote a comment, I would like it to appear instantly in the second.

All well and good, I have a sort of template where this works.

However

My system itself can sometimes add automatic notifications to the list - These are put into the database directly by a non-web based application.

How can I get SignalR to see the new information from the database and send it to the users?


回答1:


In SignalR the hub is a static part in your application. You can spin up a System.Threading.Timer in your webapplication to periodically check your database for new notifications and add those to the data used by the hub.

This can even be improved by using a SqlCacheDependency.

A subjective side note: I do agree this type of functionality is a very good candidate for SignalR.



来源:https://stackoverflow.com/questions/14568815/how-to-use-signalr-for-autorefresh-like-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!