How to call function on timer ASP.NET MVC

前端 未结 4 853
醉话见心
醉话见心 2020-12-12 14:15

I need to call function on timer (lets say onTickTack() function) and reload some info in ASP.NET MVC project. I know that there are several ways to do that, but which one i

4条回答
  •  感情败类
    2020-12-12 14:41

    You can use the Timer class in OnApplicationStart Event of Glbal.asax...

    public static System.Timers.Timer timer = new System.Timers.Timer(60000); // This will raise the event every one minute.
    .
    .
    .
    
    timer.Enabled = true;
    timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    .
    .
    .
    
    static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
      // Do Your Stuff
    }
    

提交回复
热议问题