Apppool回收和Asp.net带有线程? [英] Apppool recycle and Asp.net with threads?

查看:103
本文介绍了Apppool回收和Asp.net带有线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个执行较长sp的asp.net页面. 可以说执行sp的函数称为Func1.

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

我遇到了这个问题:

如果我在同一线程中运行了Func1(正常执行),则由于他认为应用程序池很忙/正在工作,因此该应用程序池不会自行回收.

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.

但是,如果我在另一个线程中执行Func1-则apppool会在此处设置的时间后回收自身:

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

我的问题是:为什么?

是真的吗,如果我同步运行命令,则应用处于活动状态并且不符合应用池回收的条件? 而且,如果我在新线程中创建它,那么它是否有资格进行apppool回收?

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 ?

推荐答案

ASP.NET维护用于服务请求的线程池线程的列表.它知道当没有线程处于活动状态时,它可以回收应用程序域.

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.

如果在不了解ASP.NET的情况下创建线程或使用线程池线程,它将不会检测到您的线程处于活动状态并且可能会回收.

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.

回收时,它会卸载AppDomain,这会导致在您的线程上抛出ThreadAbortException.

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

通常的解决方案是使用由Web应用程序控制的Windows服务.显然,这是在一个单独的过程中,因此不受Web应用程序回收的影响.但是,这是不平凡的练习.

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.

快速而又肮脏的解决方案是从您的Web应用程序中异步启动Web请求.然后可以开始执行操作的页面.被调用的隐藏"页面可能会阻塞,直到SP完成.正如我所说的,这是一个令人讨厌但简单的解决方案.

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.

这篇关于Apppool回收和Asp.net带有线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆