Parallel ForEach and Queues

Is it possible to have a parallel for each loop for items in the queue so that it:

  • deletes only those items that are processed
  • Pauses until new items are added to the queue.

EDIT: This applies to System.Threading.Tasks Parallel.ForEach functions

+5
source share
4 answers

Subscribe to the queue using Reactive Extensions and complete each item in a new task. You do not have to block or wait for a new element, as it will be placed in your lambda of your subscription, and your processing / processing will be parallel.

http://rxwiki.wikidot.com/101samples

+8
source

BlockingCollection :

    var bc = new BlockingCollection<int>();
Task.Factory.StartNew(() =>
    {
        ParallelOptions options = new ParallelOptions
            {
                MaxDegreeOfParallelism = 30
            };
        Parallel.ForEach(bc.GetConsumingEnumerable(), options, i => { });
    });
+1

, , , .

0

, /. , , .Net. , .Net, concurrency , Microsoft Robotics. , .

, , Google .

0

All Articles