I have a Semaphore that goes through a list of Job objects.
Here is a sample code:
List<Job> jobList = jobQueue.GetJobsWithStatus(status);
if (jobList.Count > 0)
{
foreach (Job job in jobList)
{
semaphore.WaitOne();
job.semaphore = semaphore;
ThreadStart threadStart = new ThreadStart(job.Process);
Thread workerThread = new Thread(threadStart);
workerThread.Start();
}
}
Each job object has the status member variablea (0: new, 1: inProgress, 2: completed, 3: completed withErrors).
I was wondering what is the best way to verify that all tasks in the list are complete before continuing with the script.
Note. . I tried before with ThreadPool and WaitAll, but this allows me to have a limited number of threads (no side effects) like a semaphore, and I also hit the restriction on the size of the ManualResetEvent array because it is a Windows form.
source
share