how to end a thread without an exception?

B

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?
 
J

Jeroen Mostert

buu said:
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.
 
R

Rory Becker

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top