I have a code where I have to read some Binary files in database. I wrote a For loop that iterate over my file path array, then it call a READ function that read that file into database.
I run this code with traditional for loop everything goes smooth, but then I change the for to Parallel.For and it doesn't go smooth, I adjust my code as I found lot of gray area and shared resource are creating problem in loop logic. So, I make everything Isolated to 1 Loop iteration.
Now the parallel method make my code run fast with twice the speed with one exception. The Exception is
- We have 600 files to read, out of 600 we have only 5-6 core big files.
- Out of these core big files, one or two file didn't get into the database, and no exception is generated. When I simply change Parallel.For to For they all get read, so code within it's scope is fine.
Can you suggest a method or alternative to Parallel.For, as I feel like one of core thread just die for no reason, seems impossible stuff, but this is what is happening as I am creating log at each step and different iteration shows thread stop at some other point.
Also, though I have 4Core processor it execute as many as 30 -40 files at time. I was expecting it to be like 3-4 thread at most per documentations. Any idea.