To get the behavior you need, you need to write a custom delimiter , the reason it looks βrandomβ right now, it gives the package a list of files in blocks, so if your original list was
List<string> files = List<string> { "a", "b", "c", "d", "e", "f", "g", "h", "i" };
, ( Max 3 ):
- Thread1: "a", "b", "c"
- 2: "d", "e", "f"
- Thread3: "g", "h", "i"
, ,
"a", "d", "g", "e", "b", "h", "c", "f", "i"
, , ,
- Thread1: "a",
GetTheNextUnprocessedString() - Thread2: "b",
GetTheNextUnprocessedString() - Thread3: "c",
GetTheNextUnprocessedString()
.NET 4.5, factory :
Parallel.ForEach(Partitioner.Create(_files, EnumerablePartitionerOptions.NoBuffering),
new ParallelOptions
{
MaxDegreeOfParallelism = 5 //limit number of parallel threads
},
(file, loopstate, index) =>
{
if (token.IsCancellationRequested)
return;
//do work...
});
.NET 4.5, , . MSDN, , .
, : " , ?" , , , , , , , , .