Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1043339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:39:09+00:00 2026-05-16T15:39:09+00:00

I have a Main thread that spawns around 20 worker threads. I need to

  • 0

I have a Main thread that spawns around 20 worker threads.
I need to stop the Main thread until all the other threads are finished.
I know about (thread).Join. But that only works for one thread.

and multiple Joins hurt performance like this.

t1.Join()
t2.Join()
…
t20.Join()

as the program waits one by one for each to stop.

How would I make it such that
the main thread waits for all of a set of threads to end?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:39:10+00:00Added an answer on May 16, 2026 at 3:39 pm

    You should really look into Task Parallelism (Task Parallel Library). It uses a thread-pool, but also manage task-stealing etc.

    Quote: “The TPL scales the degree of concurrency dynamically to most efficiently use all the processors that are available. In addition, the TPL handles the partitioning of the work, the scheduling of threads on the ThreadPool, cancellation support, state management, and other low-level details.” on Task Parallel Library

    You can use it like this:

    Task[] tasks = new Task[3]
    {
        Task.Factory.StartNew(() => MethodA()),
        Task.Factory.StartNew(() => MethodB()),
        Task.Factory.StartNew(() => MethodC())
    };
    
    //Block until all tasks complete.
    Task.WaitAll(tasks);
    

    Or if you use some kind of a loop to spawn your threads:

    Data Parallelism (Task Parallel Library)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that has two threads. The first one (the main thread)
I have a program that runs in a few threads. The main thread shares
I have a main application that spawns a seperate thread to process messages off
I have a program that spawns 3 worker threads that do some number crunching,
I have a main thread that invokes a child thread function at different times
I have a windows form on the main thread and another thread that does
I have code that reloads images via HTTP from the main thread and displays
I have a local thread that is started on button-click event from the main
I have a main() , which spawns a thread, and then joins to it.
Possible Duplicate: C# Spawn Multiple Threads for work then wait until all finished I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.