I'm polling an external queue for job requests, then process the job (which takes ~1 minute). Currently, I'm doing it synchronously, which is inefficient because if there were 10 jobs, it would take 10 minutes. The machine can handle up to 5 jobs at the same time, so it should be able to process 10 jobs in ~2 minutes.
I've never done multi-threading, I've tried to read about async, await, Task.Run, but haven't had any success implementing it. Any suggestions on a simple way to implement this pseudocode?
while(concurrentJobs <= 5)
{
job = pollForJob(); // synchronous
processJob(job); // want to do this in background so that I can poll for next job
}
void processJob(job)
{
concurrentJobs++;
doStuff(); // takes 1 minute
concurrentJobs--;
}