Apppool recycle and Asp.net with threads?

旧城冷巷雨未停 提交于 2019-12-06 05:33:52

问题


I have made an asp.net page which executes a long sp. lets say the the function that executes the sp is called Func1.

Ive met with that problem :

If i ran Func1 in the same thread ( normal execution), the apppool won't recycle itself since he's seeing it as a busy/working.

But if I execute Func1 in another thread - so the apppool recycle's itself after the time that is set here :

My question is : why is that ?

is it true that if i run a command synchronously , so app is active and not eligible for apppool recycle ? And if i create it in a new thread so it does eligible for apppool recycle ?

why is that ? Does the thread is less important then the main thread ?


回答1:


ASP.NET maintains a list of thread pool threads that it is using to service requests. It knows it can recycle the app domain when none of its threads are active.

If you create a thread or use a thread pool thread without the knowledge of ASP.NET, it will not detect that your thread is active and may recycle.

When it recycles, it unloads the AppDomain which causes a ThreadAbortException to be thrown on your thread.


The normal solution to your requirements is to have a windows service that is controlled by the web app. This is obviously in a separate process and so is not affected by the web app recycling. However, this is a non-trivial exercise.

The quick-and-dirty solution is to asynchronously start a web request from within your web app. The page that starts the operation can then return. The "hidden" page that was called can block until the SP has completed. As I said, this is a nasty-but-easy solution.



来源:https://stackoverflow.com/questions/8681851/apppool-recycle-and-asp-net-with-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!