What's the best implementation for more than one background service in an ASP.NET application?
Timer Callback
Timer timer = new Timer(new TimerCallback(MyWorkCallback), HttpContext, 5000, 5000);
Thread or ThreadPool
Thread thread = new Thread(Work); thread.IsBackground = true; thread.Start();
BackgroundWorker
BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(DoMyWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(DoMyWork_Completed); worker.RunWorkerAsync();
Caching like http://www.codeproject.com/KB/aspnet/ASPNETService.aspx (located in Jeff Atwood's post here)
I need to run multiple background "services" at a given time. One service may run every 5 minutes where another may be once a day. It will never be more than 10 services running at a time.
Well, instead of a 'Simple Thread', you'd go for a ThreadPool.
And if it were me, I'd run it in a Windows Service and communicate to it via MSMQ.
2.1m questions
2.1m answers
60 comments
57.0k users