views:

127

answers:

2

we have a scenario where in whil serving one asp.net request from iis from our code we have created a child thread from thread pool to servve some background task.the idea was to finsih the main thread wihich is processing the request without depending on our child thread task. But our doubt is while processing a request in asp.net will workerprocess wiat untill the thread finishes its task ?

A: 

No, if you've created a separate thread and don't have any code to wait on it, the request will certainly complete.

What I don't know is whether a worker process can be recycled while there are non-ASP.NET thread pool threads executing. I strongly suspect it can - so be aware that your child task could be terminated at any point. If this is a problem, you may wish to create a non-threadpool foreground thread.

Jon Skeet
we are using asp.net mvc will there be any difference in handling thread in asp.net mvc?
Questionevrything
No. MVC runs "inside" ASP.NET.
Gonzalo
The worker process can indeed be terminated, depending on IIS settings. I once was on a project that ran long running batch jobs as separate threads in the ASP.NET application, so I know ;) (not my design)
Pete
+1  A: 

No, the background thread will not wait for the main thread to finish, it will start immediately. If you use the Thread pool your task may have to wait for a thread to be available, but that is all.

You should however be aware that this may not be a good solution, for the application domain your asp.net site is running in may be recycled while your background thread is running. This will kill the background thread leaving the task incomplete. If it is possible, you should separate the background task into a service application that runs in a separate process. This will ensure that the task isn't killed while running.

Rune Grimstad