简体   繁体   中英

At which point in a web application can I call one method only once every 24 hours?

I need to run a code only once every 24 hours.

So, in Global.asax file: I try to put in Application_Start but when a Session ends the code is called again. I try to put in a static variable but I had the same issue. So, where can I put the code to run only once every 24 hours in my web app?

There's no reliable way to host recurring background tasks in ASP.NET applications . The correct way to do that is to host the code in a Windows Service or a console application that is scheduled to execute at regular intervals using the Windows scheduler.

Why is this a web application? If you want to run this once a day isn't this more suited to a proper application like a Windows Service?

If you HAVE to use a web application, you're going to need to store the last run date and time somewhere, like a config file or database. Once that is complete, you can set up a scheduled task to call a link on your site on a daily basis and it should just work, but you've then added a dependency on another external service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM