最佳 ASP.NET 后台服务实现 [英] Best ASP.NET Background Service Implementation
问题描述
ASP.NET 应用程序中多个后台服务的最佳实现是什么?
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();
缓存如 http://www.codeproject.com/KB/aspnet/ASPNETService.aspx(位于 Jeff Atwood 的在此处发布)
Caching like http://www.codeproject.com/KB/aspnet/ASPNETService.aspx (located in Jeff Atwood's post here)
我需要运行多个后台服务";在给定的时间.一项服务可能每 5 分钟运行一次,而另一项服务可能每天运行一次.一次运行的服务永远不会超过 10 个.
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.
推荐答案
好吧,您应该选择 ThreadPool,而不是简单线程".
Well, instead of a 'Simple Thread', you'd go for a ThreadPool.
如果是我,我会在 Windows 服务中运行它并通过 MSMQ 与它通信.
And if it were me, I'd run it in a Windows Service and communicate to it via MSMQ.
这篇关于最佳 ASP.NET 后台服务实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!