• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1370
  • Last Modified:

Thread.Join Method in C#

Hi Experts,
Could any one explain me Thread.Join Method in C# with simple examples. I tried on google but could nt find any resource to clearly understand the method
1 Solution
Tapan PattanaikSenior EngineerCommented:
Using Thread.Join  :

More often than not, you will need your application to wait for a thread to complete
execution. To accomplish this, the Thread class supports the Join method:

' VB

// C#

The Join method tells the system to make your application wait until the thread has
completed. Of course, in this simple case you do not really need a second thread
because you are just waiting for it to complete anyway. A better example is for us to
have five threads that all do some work and to wait for them. When we are working
with multiple threads, our programming task is a bit more complicated, as we need to
wait for all our threads. We can do this by keeping a reference to all our threads and
calling Join on each of the threads to wait for the threads to complete, one at a time,
as demonstrated in the following code:

// C#

ThreadStart operation = new ThreadStart(SomeWork);
Thread[] theThreads = new Thread[5];
for (int x = 0; x < 5; ++x)
// Creates, but does not start, a new thread
theThreads[x] = new Thread(operation);
// Starts the work on a new thread
// Wait for each thread to complete
foreach (Thread t in theThreads)
By storing the threads in an array, we can wait for each of the Threads one at a time. As
each thread completes, the Join method will return and we can continue.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now