T
Tony Johansson
Hi!
I'm still reading the book from Microsoft Press (exam 70-536) and there is
something that I don't fully understand.
The book says.
<start text>Controlling threads in your applications often require that you
to be able to stop threads.
The primary mechanism for stopping threads is to use the Thread.Abort
method. When the Thread.Abort method is called, the threading system
prepares to throw a ThreadAbortException in the Thread. Whether the
exception is caught or not, the thread is stopped after it is thrown. The
following code snippet provides an example. More text below the code
Thread newThread = new Thread(new ThreadStart(AbortThisThread));
newThread .Start();
newThread .Abort();
static void AbortThisThread)=
{
SomeClass.IsValid = true;
SomeClass.IsComplete = true;
SomeClass.WriteToConsole();
}
Because the AbortThisThread method never catches the ThreadAbortException,
this thread stop at the line currently executing when the main thread calls
Abort to kill the thread.<end text>
Now to my question it's the last row in the text that bother me because it
says
Because the AbortThisThread method never catches the ThreadAbortException,
this thread stop at the line currently executing when the main thread calls
Abort to kill the thread.
I mean it would have been exactly the same if the sample had caught the
ThreadAbortException meaning this thread will stop at the line currently
executing so as a summary it doesn't matter whether or not if you catch the
ThreadAbortException the thread will still stop at the line currently
executing when a Abort is done on this thread.
I'm I right or have I missed somthing ?
//Tony
I'm still reading the book from Microsoft Press (exam 70-536) and there is
something that I don't fully understand.
The book says.
<start text>Controlling threads in your applications often require that you
to be able to stop threads.
The primary mechanism for stopping threads is to use the Thread.Abort
method. When the Thread.Abort method is called, the threading system
prepares to throw a ThreadAbortException in the Thread. Whether the
exception is caught or not, the thread is stopped after it is thrown. The
following code snippet provides an example. More text below the code
Thread newThread = new Thread(new ThreadStart(AbortThisThread));
newThread .Start();
newThread .Abort();
static void AbortThisThread)=
{
SomeClass.IsValid = true;
SomeClass.IsComplete = true;
SomeClass.WriteToConsole();
}
Because the AbortThisThread method never catches the ThreadAbortException,
this thread stop at the line currently executing when the main thread calls
Abort to kill the thread.<end text>
Now to my question it's the last row in the text that bother me because it
says
Because the AbortThisThread method never catches the ThreadAbortException,
this thread stop at the line currently executing when the main thread calls
Abort to kill the thread.
I mean it would have been exactly the same if the sample had caught the
ThreadAbortException meaning this thread will stop at the line currently
executing so as a summary it doesn't matter whether or not if you catch the
ThreadAbortException the thread will still stop at the line currently
executing when a Abort is done on this thread.
I'm I right or have I missed somthing ?
//Tony