ASP.NET 4.0- Background worker - best practice

2019-04-29 05:49发布

问题:

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

回答1:

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



回答2:

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.