Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - how to end a thread without an exception?

Reply
 
Old 03-11-2008   #1 (permalink)
buu


 
 

how to end a thread without an exception?

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?



My System SpecsSystem Spec
Old 03-11-2008   #2 (permalink)
Jon Skeet [C# MVP]


 
 

Re: how to end a thread without an exception?

buu <aha@xxxxxx> wrote:
Quote:

> 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@xxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
My System SpecsSystem Spec
Old 03-11-2008   #3 (permalink)
Jeroen Mostert


 
 

Re: how to end a thread without an exception?

buu wrote:
Quote:

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

> 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.
My System SpecsSystem Spec
Old 03-11-2008   #4 (permalink)
Rory Becker


 
 

Re: how to end a thread without an exception?

Hello buu,
Quote:

> 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


My System SpecsSystem Spec
Old 03-31-2008   #5 (permalink)
a a


 
 

Re: how to end a thread without an exception?





*** Sent via Developersdex http://www.developersdex.com ***
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How do the current thread get thread notification of OS intruption .NET General
Start a new thread from an existing thread, which was started from atimer .NET General
Cross-Thread Exception .NET General
Exception stack is corrupt when catching and storing the exception .NET General
Vista Install Error: Exception Unknown Software Exception Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46