0

Original Question

C# - Parallelizing While Loop with StreamReader causing High CPU

I got an answer to use File.ReadLines from above. It seems like doing the accepted answer twice in 2 different threads cause them to share threads, but Thread 1 would do stuff with half of the threads, while Thread 2 would do nothing. Then it will reverse and repeat.

I need to do the code up to 4 times at the same time with all 10 threads running on both.

  • 2
    Can we see a code snippet? – Tommaso Belluzzo Mar 11 '18 at 14:08
  • Your performance bottleneck is likely to be the io from your disk or network. If that is the case then it doesn't matter how many processing threads are running. – Dragonthoughts Mar 11 '18 at 14:10
  • @TommasoBelluzzo The code im running is from the linked question –  Mar 11 '18 at 14:35
  • 2
    Parallelizing StreamReader is a very bad idea. Your machine has only one disk drive, it hates being jerked around by multiple threads and never lets threads run concurrently. Only ever use one thread to read, you can typically hand-off the data processing to other thread(s). That 10 of those would be "best" is fairly wishful thinking, you need to measure. – Hans Passant Mar 11 '18 at 15:10
  • It seems to be more of a ThreadPool issue or something. Is it possible that the Parallel.ForEach method would be sharing a pool of Threads? I tried using .SetMinThreads(20, 20) as theres 2 operations both using 10 threads, but I dont specifically notice a difference. –  Mar 12 '18 at 03:25

0 Answers0