[英]asp mvc reload page every 30 seconds when browser is minimized
Actually we Play a notification sound when some update happens in database, so I am trying to reload a ActionMethod
every 30 seconds when browser in minimized, this works fine in Firefox , but in Chrome this doesn't work. 实际上,当数据库中发生某些更新时,我们会播放通知声音,因此,当浏览器最小化时,我试图每30秒重新加载一个
ActionMethod
,这在Firefox中效果很好,但在Chrome中不起作用。
Scenario: 场景:
Minimize the browser and leave the computer idle. 最小化浏览器并使计算机空闲。
I have tried two methods: 我尝试了两种方法:
Method 1: 方法1:
<meta http-equiv="refresh" content="30;URL=http://example.com/" />
Method 2: 方法2:
<script>
$(document).ready(function () {
setTimeout(function(){
window.location.reload(1);
}, 30000);
});
</script>
After reading this post , It seems when Chrome is minimized it sets Javascript setInterval
and setTimeout
to an idle state, because browser performance improvements affects the executions of Javascript intervals. 阅读本文后,似乎将Chrome最小化时,它将Javascript
setInterval
和setTimeout
设置为空闲状态,因为浏览器性能的提高会影响Javascript间隔的执行。
So Can i use Scheduled Tasks like FluentScheduler , Quartz.NET or Hangfire to reload a ActionMethod
every 30 seconds ? 那么,我可以每30秒使用FluentScheduler,Quartz.NET或Hangfire之类的计划任务来重新加载
ActionMethod
吗?
Any help would be great. 任何帮助都会很棒。
SignalR is a perfect match here. SignalR在这里非常适合。 Why do you want your clients to be sending request to the server every 30 seconds?
为什么要让客户每30秒将请求发送到服务器一次? This is likely to hit your performance and increase your server load.
这可能会影响您的性能并增加服务器负载。
Instead I would suggest using SignalR and pushing notification to the client whenever there is any update. 相反,我建议您使用SignalR并在有任何更新时将通知推送到客户端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.