带有 ASP.NET Web 应用程序的后台任务
这是每 x 分钟运行一次后台作业的技术吗: http://msdn.microsoft.com/en-us/library/system.threading.threadpool.queueuserworkitem%28VS.71%29.aspx
那么我会在全局中加载它吗.asax?
Is this the technique to run a background job every x minutes: http://msdn.microsoft.com/en-us/library/system.threading.threadpool.queueuserworkitem%28VS.71%29.aspx
So would I load this in the global.asax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在后台线程上写了几个博客
http:// professionalaspnet.com/archive/2008/08/04/Creating-a-Background-Thread-to-Log-IP-Information.aspx
http:// professionalaspnet.com/archive/2009/09/21/Communication-With-a-Background-Thread-in-ASP.NET.aspx
I have written a couple of Blogs on background threads
http://professionalaspnet.com/archive/2008/08/04/Creating-a-Background-Thread-to-Log-IP-Information.aspx
http://professionalaspnet.com/archive/2009/09/21/Communication-With-a-Background-Thread-in-ASP.NET.aspx
另一种方法是拥有一个页面,当访问该页面时,该页面会执行您想要执行的任务。然后,您设置一些流程(许多托管提供商在其控制面板中提供了这样的机制),该流程每 X 分钟简单地点击该页面并强制作业运行。
Another method is to have a page that when accessed, does the task you intend to do. Then you setup some process (a lot of hosting providers provide such a mechanism in their control panel) that simple hits that page every X minutes and that forces the job to run.
不,Thread.QueueUserWorkItem 用于在线程池外的线程上排队单个工作单元。当此任务运行时,您将从 ASP.NET 中获取一个线程。执行计划任务的最佳方法可能是通过 Windows 服务,但是查看@Heinzi 建议的方法,可能适合没有大量并发用户的站点。
No, Thread.QueueUserWorkItem is for queing up a single unit of work on a thread out of the thread-pool. Whilst this task is running you are taking a thread away from asp.net. The best way to execute scheduled tasks is probably through a windows service, but look into the method suggested by @Heinzi, can be suitable for site that don't have huge numbers of concurrent users.