开发者

Run a Job in Background

I need a block of code which run a job in background. Suppose the user click on the Submit button, then a job starts in background, in the mean time the user closes that window and run a different job, an开发者_如何学运维d the job should keep running.

Please provide some help in ASP.NET and VB.NET.

Thank You Very Much For Your Help


You may take a look at the ThreadPool.QueueUserWorkItem method which allows you to run some some method on a thread drawn from the thread pool. As an alternative you could use the Thread class to spawn a new thread manually if it is a long running task to avoid jeopardizing a thread from the pool which contains a limited number of threads and which are also used to service requests in ASP.NET applications.


You can do this by creating a windows service that host a wcf service, when the user click on the submit button you can send the request to the windows service and the windows service will run in the background event the user closes the window.


A BackgroundWorker may be the easiest place to start. Put your code in the DoWork event.


You might use the BackgroundWorker, depending on your context.


BackgroundWorker will run in the background and can be easily used to sync back updates to your GUI if needed.

Or use the Task Parallel Library...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜