Limit the number of parallel threads in C#

前端 未结 5 1771
我寻月下人不归
我寻月下人不归 2020-11-28 14:58

I am writing a C# program to generate and upload a half million files via FTP. I want to process 4 files in parallel since the machine have 4 cores and the file generating t

5条回答
  •  日久生厌
    2020-11-28 15:39

    Assuming you're building this with the TPL, you can set the ParallelOptions.MaxDegreesOfParallelism to whatever you want it to be.

    Parallel.For for a code example.

提交回复
热议问题