2015年7月28日 星期二

ASP.NET System.Threading.ThreadAbortException: 執行緒已經中止

ASP.NET System.Threading.ThreadAbortException: 執行緒已經中止


Error Msg:
System.Threading.ThreadAbortException: 執行緒已經中止。     於 System.Threading.Thread.AbortInternal()     於 System.Threading.Thread.Abort(Object stateInfo)     於 System.Web.HttpResponse.AbortCurrentThread()     於 WebHRM.login.btnLogin_Click(Object sender, EventArgs e)


解決方案:https://support.microsoft.com/zh-tw/kb/918181
<%@ Page Language="C#" Async="true"%>

HttpResponse.Redirect 方法 endResponse 參數不設為 false 時,就會發生這個問題。 根據預設值,endResponse 參數設定為 true。



轉貼連結:http://www.dotblogs.com.tw/boei/archive/2010/07/11/16485.aspx
將網頁轉出成word的時候,最後會來個Response.End()來結束它的輸出,但都會發生<System.Threading.ThreadAbortException> 執行緒已經中止,雖然不會造成系統上的什麼問題。
解決方法:
1.    繼續用Response.End(),外面用try – catch包住,但try – catch會比較消耗資源,所以不考慮。
2.    改用HttpContext.Current.ApplicationInstance.CompleteRequest(),可以跳過Application_EndRequest 事件的執行。
 
如果使用Response.Redirect 或 Server.Transfer 方法也發生一樣狀況的話,就可以使用Response.Redirect(String url, bool endResponse),endResponse就設為False,因為Response.Redirect內部會用到Response.End(),設為False就是要停用Response.End()方法。

沒有留言:

張貼留言