I have a thread that ends with system.threading.thread.currentThread.Abort()
method..
.
but, it throws me an exception..
is there any other way to end a thread?

Re: how to end a thread without an exception? by Jon

Jon
Tue Mar 11 15:20:05 CDT 2008

buu <aha@a.com> wrote:
> I have a thread that ends with system.threading.thread.currentThread.Abort()
> method..
> .
> but, it throws me an exception..
> is there any other way to end a thread?

See
http://pobox.com/~skeet/csharp/threads/shutdown.shtml

Basically you should have a *graceful* shutdown mechanism.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Re: how to end a thread without an exception? by Jeroen

Jeroen
Tue Mar 11 15:27:00 CDT 2008

buu wrote:
> I have a thread that ends with system.threading.thread.currentThread.Abort()
> method..
> .
Don't do that. Ever.

> but, it throws me an exception..
> is there any other way to end a thread?
>
Sure! Just return from your thread routine and the thread will be over.

To end a thread from another thread, set a boolean, then have the thread
that needs to end check for that boolean and return from its thread routine.

The only safe (and dare I say useful) way to end a thread is by explicitly
synchronizing. There is no safe way to simply "end" a thread without knowing
what it's doing, so it's better to let the thread end itself by signaling it.

--
J.

Re: how to end a thread without an exception? by Rory

Rory
Tue Mar 11 15:28:16 CDT 2008

Hello buu,

> I have a thread that ends with
> system.threading.thread.currentThread.Abort()
> method..
> .
> but, it throws me an exception..
> is there any other way to end a thread?

Well when you start a thread you give it a procedure to run.
So you could trip some internal flag (viewable by the proc) which will allow
the procedure to come to a natural end.

--
Rory



Re: how to end a thread without an exception? by a

a
Mon Mar 31 05:11:21 CDT 2008





*** Sent via Developersdex http://www.developersdex.com ***