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 7843577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:35:11+00:00 2026-06-02T16:35:11+00:00

I am very new to threading, as a beginner in C#. I have a

  • 0

I am very new to threading, as a beginner in C#. I have a program that will be firing multiple threads inside of a windows app. My aim is to start a new thread for every item within a list. The items in this list are workstation names on anetwork. Each thread that is created will look to do repairs on each machine, when the thread has finished it will write to a log file of any errors found etc. But what i want to be able to determine is when all threads have finished. So if i have 100 machines, 100 threads, how do i determine when all have closed?

Heres my method below :-

private void repairClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
    if (machineList.Count() != 0)
    {
        foreach (string ws in machineList)
        {
            new Thread(new ParameterizedThreadStart(fixClient), stack).Start(ws);
        }
    }
    else
    {
         MessageBox.Show("Please import data before attempting this procedure");
    }
}
  • 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-06-02T16:35:16+00:00Added an answer on June 2, 2026 at 4:35 pm

    The way to do this would be to keep a reference to all the threads and then Join on them. This basically means that the current thread will block until the joined thread completes.

    Change your loop to something like:

    foreach (string ws in machineList)
    {
       var thread = new Thread(new ParameterizedThreadStart(fixClient), stack);
       _machineThreads.Add(thread)
       thread.Start();
    }
    

    (where _machineThreads is a list of System.Thread)

    You can then block until all are complete with something like:

    private void WaitUntilAllThreadsComplete()
    {
       foreach (Thread machineThread in _machineThreads)
       {
          machineThread.Join();
       } 
    }
    

    HOWEVER – you almost certainly don’t want to be doing this for the scenario you describe:

    • You shouldn’t create a large number of threads – explicitly creating hundreds of threads is not a great idea
    • You should prefer other approaches – try looking at Parallel.ForEach and System.Threading.Task. These days, .Net gives you lots of help when working with threading and asynchronous tasks – I really would advise you read up on it rather than trying to “roll your own” with explicit threads.
    • This looks like a click handler. Is it ASP.NET web forms, or a desktop application? If the former, I certainly wouldn’t advise spawning lots of threads to perform background tasks from the request. In either case, do you really want your web page or GUI to block while waiting for the threads to complete?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to threading in Python and have a couple of beginner questions.
Very new to XSL (and XML for that matter), but I need to step
I very new to Python, and fairly new to regex. (I have no Perl
Im very new to all coding including jquery. I though this would have been
I am very new to jQuery and javascript. I have an autocomplete box setup
I'm very new to PDO - only being told to head in that direction
I'm very new to Python and multithreaded programming in general. Basically, I have a
I'm a little new to threading, so you'll have to forgive the naiveté of
I have an ASP.NET app, very basic, but right now too much code to
Recently I have gone through with one simple threading program, which leads me some

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.