Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET 4.0- Background worker - best practice

I've implemented a few different types of background workers running under ASP.NET but wondered what the recommended / best practice approach might be.

In a data store (in this case a mongo db) I have a queue of actions I need to process.

The queue will grow depending upon certain actions within the ASP.NET MVC app.

I want to start a background thread / worker thread that continuously processes these queued items.

Is it as simple as kicking off a background worker in the app's start event, or should it be done on a timer?

thanks in advance

sam

like image 262
sambomartin Avatar asked Mar 13 '12 23:03

sambomartin


2 Answers

I use http://quartznet.sourceforge.net/index.html for job scheduling and have had great luck with it.

like image 140
rboarman Avatar answered Oct 15 '22 14:10

rboarman


I think the best answer is this article from Haacked.

The Dangers of Implementing Recurring Background Tasks In ASP.NET

In summary IIS is a request driven web server. Which means if there's no one hitting your website nothing will happen. You can work around it but if you want robust background tasks the recommended approach is a Windows Service.

like image 35
Daniel Little Avatar answered Oct 15 '22 13:10

Daniel Little