473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Threadabortexception

Hi
When i abort a thread i get threadabort exception and wot all the
things that need to be done there? IS releasing all the objects that
are created is necesssary before aborting?Or aborting alone is
sufficient?

Join ing the thread till it is killed is impossible in my scenario as
the exception is routed to some other layer. In the layer where abort
is done, the user will not handle it..
THanks
ANu
Jul 21 '05 #1
3 2607

"Anushya" <v_*******@hotmail.com> wrote in message
news:80**************************@posting.google.c om...
Hi
When i abort a thread i get threadabort exception and wot all the
things that need to be done there? IS releasing all the objects that
are created is necesssary before aborting?Or aborting alone is
sufficient?
It sounds like you are confusing the roles of a number of different
mechanisms. Aborting a thread injects an abort exception into the target
thread. If the abort is injected into the thread from a different thread
then it is injected asynchronously and it can interrupt a number of
execution paths, such as finally blocks and static constructors, that you
really don't want interrupted. If it is thrown by itself then it is
synchronous and so long as you understand the consequences it should not
cause harmful side-effects.

The abort causes an exception to be raised, and even if a catch block handle
the exception, once the catch block body is exited the exception will be
rethrown so the next higher catch block sees it, until all catch (and
finally) blocks have run. Eventually the thread returns from its start
method and the thread terminates.

By itself an abort does not clean up any resources nor does it call Dispose
on objects. All it does is execute catch and finally blocks until the thread
exits or the abort is reset. If you need cleanup logic then you must write
code for it.

Aborting a thread is usually not a good thing to do as it has side-effects
that can be harmful - do not use it unless you know that you wont get bit by
the side-effects. There are other methods you can use to cause a thread to
terminate, such as setting a field, signalling an event, etc. that the
thread periodically checks and if set causes it to return from its thread
start method. Also, if the thread is executing unmanaged code the abort will
not take affect until the thread returns from the unmanaged code and begins
executing managed code again.

Join ing the thread till it is killed is impossible in my scenario as
the exception is routed to some other layer. In the layer where abort
is done, the user will not handle it..


This does not make sense. Does the other layer control the thread? A
different design would be preferable to that. What would the user do to
handle an abort exception?


Jul 21 '05 #2
Thankss David,
But u say exception is rethrown from the point of abortion to start
method. In that case in huge products with lots of components inside,
we will be processing different objects which spans around hundreds of
classes.. Then in this case it is almost impossible to handle the
exception in all the methods in all the classes.. Worser may be the
sitn really, as i am talking of a single thread execution path in this
context..
The abort causes an exception to be raised, and even if a catch block handle
the exception, once the catch block body is exited the exception will be
rethrown so the next higher catch block sees it, until all catch (and
finally) blocks have run. Eventually the thread returns from its start
method and the thread terminates. So do u say the only soln is synchronous... In that case too from one
start method, the flow is again lengthy one and when the thread
aborts, the point is somewhere in some method.. how can i handle it?
even if i run a thread in background to check for the flag, how can i
return from that unknown method in unknown class????There are other methods you can use to cause a thread to
terminate, such as setting a field, signalling an event, etc. that the
thread periodically checks and if set causes it to return from its thread
start method. Many Thanks
Anushya

"David Levine" <no****************@wi.rr.com> wrote in message news:<ef**************@TK2MSFTNGP10.phx.gbl>... "Anushya" <v_*******@hotmail.com> wrote in message
news:80**************************@posting.google.c om...
Hi
When i abort a thread i get threadabort exception and wot all the
things that need to be done there? IS releasing all the objects that
are created is necesssary before aborting?Or aborting alone is
sufficient?

It sounds like you are confusing the roles of a number of different
mechanisms. Aborting a thread injects an abort exception into the target
thread. If the abort is injected into the thread from a different thread
then it is injected asynchronously and it can interrupt a number of
execution paths, such as finally blocks and static constructors, that you
really don't want interrupted. If it is thrown by itself then it is
synchronous and so long as you understand the consequences it should not
cause harmful side-effects.

The abort causes an exception to be raised, and even if a catch block handle
the exception, once the catch block body is exited the exception will be
rethrown so the next higher catch block sees it, until all catch (and
finally) blocks have run. Eventually the thread returns from its start
method and the thread terminates.

By itself an abort does not clean up any resources nor does it call Dispose
on objects. All it does is execute catch and finally blocks until the thread
exits or the abort is reset. If you need cleanup logic then you must write
code for it.

Aborting a thread is usually not a good thing to do as it has side-effects
that can be harmful - do not use it unless you know that you wont get bit by
the side-effects. There are other methods you can use to cause a thread to
terminate, such as setting a field, signalling an event, etc. that the
thread periodically checks and if set causes it to return from its thread
start method. Also, if the thread is executing unmanaged code the abort will
not take affect until the thread returns from the unmanaged code and begins
executing managed code again.

Join ing the thread till it is killed is impossible in my scenario as
the exception is routed to some other layer. In the layer where abort
is done, the user will not handle it..


This does not make sense. Does the other layer control the thread? A
different design would be preferable to that. What would the user do to
handle an abort exception?

Jul 21 '05 #3

"Anushya" <v_*******@hotmail.com> wrote in message
news:80*************************@posting.google.co m...
Thankss David,
But u say exception is rethrown from the point of abortion to start
method. In that case in huge products with lots of components inside,
we will be processing different objects which spans around hundreds of
classes.. Then in this case it is almost impossible to handle the
exception in all the methods in all the classes.. Worser may be the
sitn really, as i am talking of a single thread execution path in this
context..


That isn't quite what I said, and it isn't clear what you are asking.

The abort causes an exception to be raised, and even if a catch block handle the exception, once the catch block body is exited the exception will be
rethrown so the next higher catch block sees it, until all catch (and
finally) blocks have run. Eventually the thread returns from its start
method and the thread terminates.

So do u say the only soln is synchronous... In that case too from one
start method, the flow is again lengthy one and when the thread
aborts, the point is somewhere in some method.. how can i handle it?
even if i run a thread in background to check for the flag, how can i
return from that unknown method in unknown class????


No, I am not stating that you must use it synchronously, just that doing so
is preferred because injecting an abort asynchronously has side-effects that
can cause problems.

Do you want to interrupt a thread that is executing code written by
yourself and over which you have control, or are you trying to arbitrarily
interrupt a thread executing code written by an unknown third party where
you do not know what the code is actually doing? Also, the execution state
of a thread is completely unrelated to the state of other objects. If you
need certain objects to be cleaned up when the thread is terminated then you
will have to write the code yourself to make this happen.

It isn't at all clear to me what you are trying to accomplish.
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Vivek | last post by:
Hi, I have a question regarding ThreadAbortException. Why is the thread abort exception rethrown at the end of a catch clause? Why is ThreadAbortException's behavior designed to be this way? ...
6
by: David Waz... | last post by:
Moved an app from W/2000 Asp V1.0 to W/2003, VS/2003, ASPV 1.1 Page runs a long job, uploading 2 large fixed length files (300,000 rows) into SQL database. A process is run against the data,...
0
by: Chee | last post by:
Hi all Please forgive me if this has been asked before. I am getting a ThreadAbortException in "Unknown Module" when i try to load a page from VS.NET. One problem is it does not happen all the...
3
by: Steve - DND | last post by:
I just implemented a page that performs a Response.Redirect(url, true). As such, I wrapped it in a try catch, and explicitly caught a ThreadAbortException. However, the thread abort exception was...
4
by: splap20 | last post by:
Every day a large chunk of XML is posted up to my app via http. The app interprets this XML and writes results to a SQLServer. Occasionally a ThreadAbortException is thrown during this process....
1
by: Eric | last post by:
I have the following situation: I was getting intermittent errors using Reponse.Redirct("url", true) and was trying to catch the ThreadAbortException, but it was not staying caught and was showing...
1
by: Burak Gunay | last post by:
Hello, I have a piece of code where I am writing the contents of a datagrid to an excel report Dim tw As New StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) Dim frm As HtmlForm...
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
3
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I am running a web service which sometimes throws exceptions. I have a lot of error trapping within the web service, but I have missed the current problem. I am working on the current issue,...
0
by: Zeba | last post by:
Hi ! I am using a httphandler to perform some url rewriting in my application. My web.config contains the following entry to direct all urls containing /App/*.ashx to my class AppHandler.cs in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.