使用SignalR定期刷新数据,而不是广播给客户端 [英] Refreshing data periodically using SignalR rather than broadcasting to clients

查看:83
本文介绍了使用SignalR定期刷新数据,而不是广播给客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上显示一些数据,即Sum,Average和Total,并希望在使用SignalR更改数据后进行更新.大多数示例使用以下方法在执行创建/更新/删除方法(更改数据)后广播所有客户端:

I display some of the data i.e. Sum, Average and Total on a page and want to update them after the data changed using SignalR. Most of the examples uses the following approach that broadcast all of the clients after create / update / delete methods (that change data) are executed:

private void BroadcastDataChange(Data data)
{
    Clients.All.dataChanged();
}

但是,我想知道是否有一种更聪明的方法可以让我更新数据,即在每个create-update-delete方法中定期广播而不进行广播(我不使用SqlDependency等,而是使用SignalR突出显示).另一方面,我不确定这种方法是否与SignalR逻辑相矛盾.这是我第一次使用SİgnalR,我很困惑:(任何帮助将不胜感激.

However, I am wondering if there is a smarter approach that let me update the data i.e. periodically refreshing without broadcast in each of the create-update-delete methods (I do not use SqlDependency, etc, juts using SignalR). On the other hand, I am not sure this kind of approach is contradictory to the SignalR logic. This is the first time I use SİgnalR and I am too confused :( Any help would be appreciated.

推荐答案

您可以对SignalR使用轮询.但是,这只是一种低效的处理方式,因为:(1)发生更改的时间与向客户端广播更改之间会有延迟. (2)即使数据没有更改,广播仍会发生,这是对资源的浪费.

You can use polling with SignalR. It's just an inefficient way of doing things though, because: (1) there would be a delay between when changes happen and when they are broadcast to clients. (2) broadcasts would happen even if data didn't change, which is a waste of resources.

这篇关于使用SignalR定期刷新数据,而不是广播给客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆