At the moment I have List of Job objects that are queued to be processed sequentially shown in the code bellow.
List<Job> jobList = jobQueue.GetJobsWithStatus(Status.New);
foreach (Job job in jobList)
{
job.Process();
}
I am interested in running several Jobs at the same time in a limited number of threads (lets say 5 threads).
What is the best way to do this in c#?
Additional Notes:
- A Job object does not share resources with other jobs.
- Each Job takes about 10 seconds to process.
- Each job could connect to different resources.
Update: I have used a Semaphore because I could not limit the amount of active threads with a ThreadPool.