
What is the purpose of Thread.Join() method in .NET?Thread.Join()
method belongs to System.Threading namespace. If you want a thread to
wait until another thread finishes its execution, then you can do it using
Thread.Join(). Assume that you have two threads namely sample1Thread and
sample2Thread. You have started sample1Thread and then started sample2Thread. What if sample2Thread
runs for a long time and sample1Thread cannot wait until it gets completed,
then instead of calling sample2Thread.join(), you can call sample2Thread.join(10000)
where 10000 means that sample1Thread will wait for next 10 seconds within
which it expects the sample2Thread to finish its execution. If sample2Thread
couldnt finish its job in 10 seconds, then the sample1Thread will
continue its execution even if sample2Thread is still executing. Here is an
example that makes main Thread to wait until sampleThread finishes its
execution: class sampleClass
{ Output of
this code will be: In sample Continues
execution of main thread
_______________________________________________________________________
FREE
Subscription
Subscribe
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________ |