Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Thread.Join()
Message
From
08/07/2005 14:40:42
Keith Payne
Technical Marketing Solutions
Florida, United States
 
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
01030642
Message ID:
01030667
Views:
16
>What is the purpose of Thread.Join() other than waiting for the thread to complete? Does it serve any other purpose? Is it bad on to Join() a thread?
>
>The reason I am asking is that I expected the ininite thread to stop after 4 seconds when I issue myThread.Join(4000), but the thread keeps on going.
>I guess if I really want my thread to stop I have to do something like this:
>
>myThread.Join(4000);
>myThread.Abort();
>
>
>but then I noticed the litte paragraph in the Thread.Abort help stating: Calling this method usually terminates the thread
>
>Thanks,
>Einar

Einar,

It is a rare occurence that a thread will not terminate after it is Aborted. You should check Thread.IsAlive in a loop with a Sleep call that runs for 4 seconds before joining the thread, then Abort the thread if it is still alive, then Join to the thread to wait for the Abort to finish. Joining before the abort will cause the current thread to sit and wait for the other thread to finish executing - which may not happen quickly.

When you start a new thread, you are no longer in control of the thread. It is on its own. The only thing you can do is to request that the thread do something - like Abort itself and wait for whatever callback functions you hooked into it. Unless you have gone out of your way to design code that will cause the thread not to Abort in a timely manner, you will be safe.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform