Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

timer on web app

i want my website(C#) will call async every 15 min to some c# function how can i do that?

thanks

like image 792
avnic Avatar asked Dec 13 '22 06:12

avnic


1 Answers

You can use a static Timer and start it from the Application_Start() method in Global.asax.

Within Global.asax, add the following field:

static Timer _timer = null;

Then you can make your Application_Start() like:

void Application_Start(object sender, EventArgs e)
{
    if (_timer == null)
    {
        _timer = new Timer();
        _timer.Interval = 1000; // some interval
        _timer.Elapsed += new ElapsedEventHandler(SomeStaticMethod);
        _timer.Start();
    }
}
like image 158
kfuglsang Avatar answered Dec 27 '22 07:12

kfuglsang