How to configure a maximum number of threads in a Parallel.For

后端 未结 3 798
执念已碎
执念已碎 2021-01-01 12:00

This is the example microsoft presents for the parallel for, and I\'d like to know how configure a maximum number of threads for this code.

     // A basic m         


        
3条回答
  •  盖世英雄少女心
    2021-01-01 12:20

    Use MaxDegreeOfParalelism property for running the loop

    Parallel.For(0, 1000, new ParallelOptions { MaxDegreeOfParallelism = 2 }, ...);
    

提交回复
热议问题