【发布时间】:2010-02-02 00:10:11
【问题描述】:
有人知道为什么 ASP.NET 可能不会使用 Response.End() 中止当前线程吗?
更新:原因是在 Response.End() 之后执行了一些代码,尽管写得不好。我从未见过 Response.End () 没有阻止当前线程执行的情况。
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.Redirect("somewhere", true);
Response.End();
//Some other code get's executed here
}
【问题讨论】:
-
为什么会中止线程?当然,该线程只会回到线程池中。 (警告:自 1999 年以来,我没有研究过 ASP 的线程模型;自从我上次查看该代码以来,情况可能已经发生了变化。)
-
Response.End() 确实中止了线程。 support.microsoft.com/kb/312629
-
@Cheeso,它应该,但我的情况是有些事情正在阻止。 Rick Strahl 有一个小代码 sn-p,它显示了一个不会中止当前线程的潜在情况。 west-wind.com/WebLog/posts/368975.aspx
-
@Trent,但即使他也不知道它为什么起作用,这有点微妙的错误 - 看看它应该如何工作,应该继续引发异常在他接球之后,仍然没有记录他的横幅呼叫。
-
@Zhaph,我真的指的是他概述的 MS 正在做什么的代码 in response.end():: public void End() { if (this ._context.IsInCancellablePeriod) { InternalSecurityPermissions.ControlThread.Assert(); Thread.CurrentThread.Abort(new HttpApplication.CancelModuleException(false)); } else if (!this._flushing) { this.Flush(); this._end = true; if (this._context.ApplicationInstance != null) { this._context.ApplicationInstance.CompleteRequest(); } } }