|
Subject:
|
Thread was being aborted
|
|
Posted By:
|
acko
|
Post Date:
|
11/3/2003 5:13:31 AM
|
Hi, I have the folowing code
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Try Response.Redirect(Application("sRoot") & "Prva.aspx")
Catch ex As Exception Dim Greska As String Greska = ex.Message Greska = ex.ToString() Response.Redirect(Session("sRoot") & "GlobalError.aspx?ER=" & Greska)
End Try
A few days ago this code worked just fine and i could go to Prva.aspx, but now i always get Exception (Thread was being aborted) and go to GlobalError.aspx. Why? Thanks, Alex
|
|
Reply By:
|
planoie
|
Reply Date:
|
11/3/2003 10:13:52 AM
|
Have you changed anything in the application in the last few days? There seems little reason for this to suddenly change unless you made some change with the configuration of the application.
One thing I can point out is that you usually should need to convert what you get from "Application()" into the appropriate data type before using it...
Response.Redirect(CType(Application("sRoot"), String) & "Prva.aspx")
Another suggestion is that if you want to reference a page based on your application root, you can do this:
Response.Redirect(ResolveURL("~/Prva.aspx"))
~ reference the application "home" directory, or the vitual directory. So no matter where this code is called from, the resulting value passed to the redirect will be something like "/MyWebApp/Prva.aspx".
Peter
|
|
Reply By:
|
inancgumus
|
Reply Date:
|
11/6/2003 9:47:44 AM
|
The reason for the error is Response.Redirect method.
If you want to get rid of this exception, use Response.Redirect(url, false).
Instead of putting Response.Redirect into Try..Catch block. You may try this one:
Dim url As String
Try url = Application("sRoot") & "Prva.aspx" Catch ex As Exception Dim Greska As String Greska = ex.Message Greska = ex.ToString() url = Session("sRoot") & "GlobalError.aspx?ER=" & Greska End Try
Response.Redirect(url, False)
Sorry I didnt used to VB.Net, and some syntax error(s) may be occurred.
-----------------------------------------------
I'm going to write some about the situation; it may clarify your mind if you have some patience to read.
Your page is executing by a thread on which asp.net worker process contains. And on some line in your code, an instruction (Response.Redirect) wants to stop the execution because it must be stopped and asp.net framework must be notified about a redirection request.
Asp.net framework catches the Redirect method's exception, aborts the thread and use a new thread for execution of to be redirected page.
This occurs when you specify the second argument of Redirect method as True. Because this means to asp.net framework as 'Stop this page's execution ASAP and execute to be redirected page'.
... Yesterday, I forgot to write down something about special exception class named ThreadAbortException.
You are getting this exception because Response.Redirect method internally calls Response.End method which raises this exception and the page processing terminates. Response.End raises this exception indirectly through calling Thread.Abort which raises this exception directly.
This exception is a special exception as I have said. The common language runtime has a special attention for this exception. When this exception occurs you can catch it in a catch block of a try...catch structure. And this exception will be raised again by the runtime at the end of the catch block. So, as you see, this is the reason why you are getting this exception even you were encapsulating Response.Redirect in a try...catch block.
Inanc Gumus
Software Architect
can be reached at inancgumus@hotmail.com
|
|
Reply By:
|
acko
|
Reply Date:
|
11/9/2003 12:51:57 PM
|
Thanks a lot Alex
|
|
Reply By:
|
gueladio
|
Reply Date:
|
12/11/2004 12:55:16 PM
|
I am calling a web service from asp.net (both written in VB.NET). When I call the web service I get a ThreadAbortException (ex.message thread was being aborted)
This problem does not occur however if I call the same web service from a windows app. Now this web service and asp.net application is hosted offsite and I dont have access to the machine.config file to lengthen the timeout for the web session (let alone restart IIS).
Is there anything I can do to prevent this from happening???
Thanks in advance.
|
|
Reply By:
|
rstelma
|
Reply Date:
|
3/22/2006 6:33:02 PM
|
Inanc Gumus,
Thanks so much for your post. I was getting the same error. Took the response.redirect out of the Try.. Catch block and no more exception.
Very much appreciated.
Thanks, Richard
|
|
Reply By:
|
Ulf Lunde
|
Reply Date:
|
8/22/2006 8:40:09 AM
|
quote: Originally posted by gueladio
I am calling a web service from asp.net (both written in VB.NET). When I call the web service I get a ThreadAbortException (ex.message thread was being aborted)
It is probably the ASP.NET server on the calling side that terminates the application. If so, adding a line like this to your local Web.config file should make the error go away:
<httpRuntime executionTimeout="300"/> <!-- timeout in seconds -->
 Ulf Lunde
|
|
Reply By:
|
anoop.goyal
|
Reply Date:
|
10/9/2006 6:13:45 AM
|
This may be solution for specific problems.
But when i send mail and then redirect to a page, it will skip the mail sending and goes to redirected page. But i want to send mail also.
How can i do it?
|
|
Reply By:
|
dparsons
|
Reply Date:
|
10/9/2006 9:10:07 AM
|
Are you calling SmtpMail.Send(mail) before you redirect?
--Stole this from a moderator
I will only tell you how to do it, not do it for you. Unless, of course, you want to hire me to do work for you.
|
|
Reply By:
|
Charu26
|
Reply Date:
|
11/27/2006 3:11:15 AM
|
quote: Originally posted by inancgumus
The reason for the error is Response.Redirect method.
If you want to get rid of this exception, use Response.Redirect(url, false).
Instead of putting Response.Redirect into Try..Catch block. You may try this one:
Dim url As String
Try url = Application("sRoot") & "Prva.aspx" Catch ex As Exception Dim Greska As String Greska = ex.Message Greska = ex.ToString() url = Session("sRoot") & "GlobalError.aspx?ER=" & Greska End Try
Response.Redirect(url, False)
Sorry I didnt used to VB.Net, and some syntax error(s) may be occurred.
-----------------------------------------------
I'm going to write some about the situation; it may clarify your mind if you have some patience to read.
Your page is executing by a thread on which asp.net worker process contains. And on some line in your code, an instruction (Response.Redirect) wants to stop the execution because it must be stopped and asp.net framework must be notified about a redirection request.
Asp.net framework catches the Redirect method's exception, aborts the thread and use a new thread for execution of to be redirected page.
This occurs when you specify the second argument of Redirect method as True. Because this means to asp.net framework as 'Stop this page's execution ASAP and execute to be redirected page'.
... Yesterday, I forgot to write down something about special exception class named ThreadAbortException.
You are getting this exception because Response.Redirect method internally calls Response.End method which raises this exception and the page processing terminates. Response.End raises this exception indirectly through calling Thread.Abort which raises this exception directly.
This exception is a special exception as I have said. The common language runtime has a special attention for this exception. When this exception occurs you can catch it in a catch block of a try...catch structure. And this exception will be raised again by the runtime at the end of the catch block. So, as you see, this is the reason why you are getting this exception even you were encapsulating Response.Redirect in a try...catch block.
Inanc Gumus
Software Architect
can be reached at inancgumus@hotmail.com
Thank you for the useful insight. I had the same problem and solved it too. Thank you again. :) Keep up the good work.
|
|
Reply By:
|
Hannibal
|
Reply Date:
|
12/13/2006 1:50:15 AM
|
I am getting the "Thread was being aborted" when i use the Response.redirect in the catch block. Is there any way i can use the Response.Redirect in the catch block? This is my catch block code :
catch (Exception ex) { LogReport.ErrorReport(this.GetType().Name + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + ":" + ex.Message); Response.Redirect("Logindms.aspx",false); }
please help
|
|
Reply By:
|
dparsons
|
Reply Date:
|
12/13/2006 8:31:01 AM
|
Thats extremely weird because I call Response.Redirect in all of my catch blocks and do not raise this error; are you sure its this line that is causing the error?
------------------------- I will only tell you how to do it, not do it for you. Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|
Reply By:
|
ricardotineo
|
Reply Date:
|
4/19/2007 2:20:16 PM
|
Check this... http://support.microsoft.com/?scid=kb%3Ben-us%3B312629&x=10&y=15
|
|
Reply By:
|
kashyap.2000
|
Reply Date:
|
5/29/2008 4:03:50 AM
|
Thank you very much .... i too was facing the same problem ,i removed response.redirect from try catch block and all problems got solved...Jai hind
|