views:

73

answers:

3

I need reliable way to run 10 different tasks simultaneously. For instance the first one would be sending emails, while the next one is cleaning rows from a specific table... so on an so forth.

I've used the Thread class and while it works well on my development machine (VS2010 internal web server) non of these threads seems to be working at all on my production server. And I don't know of an effective way to debug the problem on the production server.

I saw this technique which encourage you to register cache objects. Since the application fires a callback when a cached item expires, then it's possible to run any code to mimic threading behavior. It seems a little Micky Mouse like.


I guess my questions is what is the correct way to indefinitely run background tasks in an ASP.NET MVC2 applications?

+1  A: 

There's certainly a lot of ways. Here's one.

Implement your long running tasks as a windows service , send messages about stuff-to-do to that service from your ASP.NET application using MSMQ,

nos
+4  A: 

The best way is to not run them within ASP.net code. This sounds like an ideal task for a scheduled task, or a windows service. ASP.net (MVC or otherwise) is not really set up for doing this - split them out to a separate project.

Paddy
I second that: Create a Console app and reference your library. Compile into an executable. Use the Task Schedular to run the .exe at intervals. This of course requires you have access (and control over) the hosting server.
Jakob Gade
A: 

I have been using quartz.net for this before and it has worked out pretty well.

Mattias Jakobsson
@nos, I looked at quartz.net. Does this have a dependency on a database? I mean does it require a database to work?
Am
@Am, No, it doesn't. But you can use a database to store the tasks if you want to.
Mattias Jakobsson