Limit the number of parallel threads in C#

前端 未结 5 1775
我寻月下人不归
我寻月下人不归 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:36

    If you are using .Net 4.0 you can use the Parallel library

    Supposing you're iterating throug the half million of files you can "parallel" the iteration using a Parallel Foreach for instance or you can have a look to PLinq Here a comparison between the two

提交回复
热议问题