Multi threading which would be the best to use? (Threadpool or threads)

前端 未结 7 1595
醉梦人生
醉梦人生 2021-01-07 02:52

Hopefully this is a better question than my previous. I have a .exe which I will be passing different parameters (file paths) to which it will then take in and parse. So I w

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 03:06

    See this question for how to find out the number of cores.

    Then use Parallel.ForEach with ParallelOptions with MaxDegreeOfParallelism set to the number of cores.

    Parallel.ForEach(args, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, (element) => Console.WriteLine(element));
    

提交回复
热议问题