I built an OCR application which reads PDF files and OCR's them. I built it using Multi-threading with the Parallel.ForEach function.
This works brilliantly, but I noticed that the way the threads are divided seems to work differently to what I'm expecting.
Scenario: When allocating only 10 threads using MaxDegreeOfParallelism, it divides the workload and I can see 10 threads being immediately started. However, there are 100 items that needs to be processed. When it gets around 80/100 items processed, it slows down by only running 2 out of the 10 threads. I suspect this is due to 8/10 threads have successfully completed their portion of the work, but because some PDFs took longer on a certain thread, that thread is still processing his portion of the work.
So my question is, how can I write this better so that even if it does get to 80/100, there should ALWAYS be 10 active threads... (of course when it gets to 90+ the threads will die down, but at least it wont process 1 by 1 when the last thread still has workload to complete.
I hope this makes sense. Here is a snippet of my code:
Parallel.ForEach(F.files, new ParallelOptions { MaxDegreeOfParallelism = iNumberOfThreads }, items =>
{
//do work here
}
});
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)