0

I'm looking for a way to call a function every N seconds in order to update data displayed on the page.

Is there a built-in functionality to accomplish this task or do I have to do it by myself?

2 Answers 2

3

There are the window.setTimeout and window.setInterval javascript functions. For example:

window.setInterval(function() {
    // this will run on every 10 seconds
    // Here you can send AJAX requests to your controller actions in order 
    // to refresh some data
}, 1000 * 10);
Sign up to request clarification or add additional context in comments.

Comments

0

Timer class:

using System.Timers;
...

_timer = new Timer(3000); // Set up the timer for 3 seco
_timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
_timer.Enabled = true; // Enable it


static void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
   // do stuff
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.