开发者

Is there a timer function in ASP.NET MVC3?

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 accomp开发者_JAVA技巧lish this task or do I have to do it by myself?


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);


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜