The very essence: there is an array of strings, there is a method that takes 1 string and works with it, the result of the method execution can be positive or negative. Purpose: It is necessary to call a method in several threads (with the possibility of restricting threads) (sending an entire new line from the array) for now:

  1. Do not run out of string array

    OR

  2. Run successfully n lines. For example, in an array of 100 lines, n = 10, once the method has been successfully completed, we complete the work 10 times.

So far, I was able to implement everything except paragraph 2

CancellationTokenSource cts = new CancellationTokenSource(); var opt = new ParallelOptions { CancellationToken = cts.Token, MaxDegreeOfParallelism = kolthread //ΠΊΠΎΠ»-Π²ΠΎ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΏΠΎΡ‚ΠΎΠΊΠΎΠ² }; Parallel.ForEach(lines, opt, a => Metod(a));//lines- массив строк 

Can you help implement point 2?

  • one
    Keep the counter, if the counter is greater than or equal to 10 - terminate the streams. - Vladimir Martyanov
  • @ Vladimir Martianov Yab introduced, but how to complete the creation of new streams Parallel.ForEach(lines, opt, a => Metod(a)); ? - Lolidze
  • one
    And CancellationToken not for this purpose? - Vladimir Martyanov
  • one
  • one
    msdn.microsoft.com/en-us/library/ ... You can limit this parameter from above, but you cannot specify the number of threads that will be used, so if you do not need a restriction from above, then do not change it. - rdorn

0