How to run automatic "jobs" in asp.net?

I want my site to do a few calculations every 10 minutes, and then update the database with the results. How exactly do I set such a timer, I assume it will be in global.asax?

+3
source share
6 answers

Doing something like this in a web application is somewhere between difficult and unstable to impossible. Web applications are simply not designed to run non-stop, only to respond to requests.

Do you really need to do the calculations every ten minutes? I found that in most cases when someone asks such a question, they really just need something to work at intervals, but so far no one visits the page to see the results, the results do not really need to be calculated.

If this is the case in your case, then you just need to keep track of when the calculations were last performed, and for each request, check if there is enough time to recount.

+4
source

You better write a separate application other than the UI and then run it as a scheduled task.

+4
source

() - , :

global.asax, application.onstart, :

var dueTime = 5000;
var period = 5000;
var MyTimer = new Timer(new TimerCallback(MyClass.MyTaskProc), null, dueTime, period);
Application["MyTaskTimer"] = MyTimer;

,

+3

, . , , , SQL Server .

+2

Cache cagdas. . , , - . , , .

  • SQL Server
  • Windows.
0

I really don't like the scheduled tasks. I would prefer to use this feature in a Windows service and throw a timer into it. With the help of window services, you can perfectly handle stop events. I agree with everyone, the site is not for this.

0
source

Source: https://habr.com/ru/post/1705487/


All Articles