开发者

background task with an asp.net web application

开发者 https://www.devze.com 2022-12-09 07:51 出处:网络
Is this the technique to run a background job every x minutes: http://msdn.microsoft.com/en-us/library/system.threading.threa开发者_高级运维dpool.queueuserworkitem%28VS.71%29.aspx

Is this the technique to run a background job every x minutes: http://msdn.microsoft.com/en-us/library/system.threading.threa开发者_高级运维dpool.queueuserworkitem%28VS.71%29.aspx

So would I load this in the global.asax?


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号