0

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.

Scenario:

Minimize the browser and leave the computer idle.

I have tried two methods:

Method 1:

   <meta http-equiv="refresh" content="30;URL=http://example.com/" />

Method 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.

So Can i use Scheduled Tasks like FluentScheduler , Quartz.NET or Hangfire to reload a ActionMethod every 30 seconds ?

Any help would be great.

Community
  • 1
  • 1
Shaiju T
  • 6,201
  • 20
  • 104
  • 196
  • 2
    For scenario like that I would go wihh pushing notifications to the page instead of polling every 30sec. You can use libraries like SignalR for client-server communication – Hassan Jul 16 '16 at 12:08
  • @Massanu , Thanks , finally i went with signalR and everything works fine, [here](http://stackoverflow.com/a/38587725/2218697) is my solution. – Shaiju T Jul 26 '16 at 11:03

1 Answers1

1

SignalR is a perfect match here. Why do you want your clients to be sending request to the server every 30 seconds? 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.

  • Yes you are correct , and i have started using `SignalR` but i have a problem, as mentioned in question and [here](http://stackoverflow.com/questions/22061280/javascript-halts-in-inactive-android-chrome-tab) for performance reasons chrome browser disables JavaScript while its inactive. so some our clients keep the browser minimized , and when i send notification to client using `SignalR` and try to play a sound by calling a `JavaScript` function, it doesn't work. Any suggestion ? – Shaiju T Jul 22 '16 at 12:09
  • In Godaddy shared hosting because they restrict some features, so i was unable to use `SqlDependency`, but [here](http://stackoverflow.com/a/38587725/2218697) is my solution to **Play notifications without SqlDependency using SignalR**, it works even when browser is inactive or minimized. This **reloads partial view** when new notification comes. – Shaiju T Jul 26 '16 at 11:00