in Education by
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)

1 Answer

0 votes
by
Thanks to Panagiotis Kanavos, I've implemented ActionBlock, which resolves my problem. var getData = new ActionBlock(items => { //Code Here }, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = iNumberOfThreads }); foreach (JsonPDFReader.File items in F.files) { getData.Post(items); } getData.Complete(); getData.Completion.Wait();

Related questions

0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    How do I implement a Copy menu item in a Windows application written in C#/.NET 2.0? I want to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    If I am trying to determine the read speed of a drive, I can code a routine to write files to a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    How can you strip non-ASCII characters from a string? (in C#) JavaScript questions and answers, JavaScript ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I want create expression with reflection in c#. I am target script is: using (var service = new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    Hi Folks i was googling one more hours.i did not find anything relevant, I have text File like ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I have 2 Tables, Receipts which contains columns like Id, InvoiceId etc and Invoices, which Contains Id, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    I have 2 Tables, Receipts which contains columns like Id, InvoiceId etc and Invoices, which Contains Id, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    F# allows constraining generic types on the type's members, similar to: type ClassWithMemberConstraint = class end ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Is there any simple way to repeat code in a try/catch block after an exception occurs without using method ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I am a very novice C# person so please dont be too hard on me Im trying to make a post request ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a dataset, "AllEventData", and in that dataset is (for the moment) only one table called ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Im facing a litle problem in Deserializing BsonDocuments type, I couldn't find the reason, but I have some ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    Someone please correct me if I'm wrong, but parsing a yyyy/MM/dd (or other specific formats) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 26, 2022 in Education by JackTerrance
...