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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:30:33+00:00 2026-05-13T21:30:33+00:00

I have a Semaphore that runs trough a list of Job objects. Here is

  • 0

I have a Semaphore that runs trough a list of Job objects.

Here is a sample of the code:

List<Job> jobList = jobQueue.GetJobsWithStatus(status);
if (jobList.Count > 0)
{
  foreach (Job job in jobList)
  {
    semaphore.WaitOne();

    // Only N threads can get here at once
    job.semaphore = semaphore;
    ThreadStart threadStart = new ThreadStart(job.Process);

    Thread workerThread = new Thread(threadStart);
    workerThread.Start();
  }

  //check that every thread has completed before continuing
}

Every job object has a status member variablea (0: new, 1: inProgress, 2: completed, 3: completedWithErrors).

I was wondering what is the best way to check that every job in the list has completed before continuing with the script.

Note: I tried before with a ThreadPool and WaitAll, but It doenst allow me to have a limited amount of threads (without secondary effects) like a semaphore does, and I also hit a limitation of the size of the ManualResetEvent array because it is a Windows Form.

  • 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-13T21:30:34+00:00Added an answer on May 13, 2026 at 9:30 pm

    You can normally call Thread.Join on each thread in a separate foreach loop.

    By the way, you can combine the semaphore with the thread pool: have each work item wait on the semaphore before doing any work.

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

Sidebar

Related Questions

At the moment I have List of Job objects that are queued to be
I have some very basic semaphore code that works great on Linux, but cannot
I have a program that creates semaphore. But when i try to use SETALL,
I have multiple threads that share use of a semaphore. Thread A holds the
Is it possible to have a fair semaphore in python, one that guarantees that
I have some code that generates threads (lizards) it also makes a cat thread.
I have a semaphore that I tried to change the value of and it
I have a process that runs continuesly. I want to trigger that process every
I have program that uses shared memory and protects it with semaphore to communicate
I have an array that must be shared between threads, protected by a semaphore.

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.