最佳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
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(DoMyWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(DoMyWork_Completed);
worker.RunWorkerAsync();
缓存如 HTTP://www.$c$cproject .COM / KB / ASPNET / ASPNETService.aspx (位于杰夫阿特伍德的的后这里)
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.
推荐答案
好了,而不是一个简单的线程',你会去一个线程池。
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屋!