Repeated ASP.NET MVC Task

I need to run a task multiple times on an ASP.NET MVC site; it should run every time interval (the interval does not matter).

I achieved this by setting the background thread from the Global_asax.cs Application_Start application, which starts the task, sleeps for the time interval, and then starts again .... and again.

While this works, it doesn't seem like the right way to do this, seems a bit hacked.

So, I replaced it with a Timer object, this does not work reliably - others seem to have problems with it, so I will not use this.

This needs to be launched on the MVC website, it is used to pull tasks out of the queue and render them from the views ready to be sent by email.

I thought about using ThreadPool and letting the previous task leave another task on it, but since it might be lengthy tasks that I read, it may end up not leaving enough threads to handle web requests with hunger.

Before sticking to the source thread method, I thought I'd ask if anyone knew an even better way to do this.

Hope this makes sense. Effectively what I am trying to achieve is a heartbeat. Something must act as the consumer part of the producer / consumer pattern on the MVC website.

+5
source share
2 answers

Stackoverflow (, , ) . . : http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

, :

  • HttpRuntime.Cache .

  • , , WebRequest .

  • .

+9

, , :

MVC

, , , .

Windows , . .

, MVC?

0

All Articles