Parallel pipeline in C #

I want to create a parallel pipeline in C #. I declared an interface called IOperation:

public interface IOperation<Tin, Tout>
{
    BlockingCollection<Tout> BlockingCollection(IEnumerable<Tin> input);
}

Now I want to write a class that performs several of these operations in parallel. I am cursed by this:

public class Pipeline : IPipeline
{
    private List<IOperation<Object, Object>> operations = new List<IOperation<Object, Object>>();
    private List<BlockingCollection<Object>> buffers = new List<BlockingCollection<Object>>();
    public void Register(IOperation<Object, Object> operation)
    {
        operations.Add(operation);
    }

    public void Execute()
    {

    }
}

But I did not find a solution to save operations and buffers between operations, because they have all different types. Anyone have an idea?

+3
source share
4 answers

Have you considered using Parallel.ForEach from TPL?
Parallel Task Library (TPL) is a collection of public types and APIs in .NET 4.

+1
source

, Pipeline . BlockingCollections? , object ?

, , Pipeline, Action, , .

public void Register(Action operation)
    {
        operations.Add(operation);
    }

public void Execute()
    {
        foreach (var action in operations)
          Task.StartNew(operation);
    }

"", , .

, , . , - PipelineStep<T,U>, , Func. IEnumerable IEnumerable, Task foreach.

TPL Task.ContinueWith .

+1

Microsoft : TPL Dataflow , .

, push. BlockingCollection ( ) , .

+1

The article http://msdn.microsoft.com/en-us/library/ff963548.aspx has a good article on parallel pipelines with BlockingCollection.

Basically, each step should have an output queue of type BlockingCollection. It takes elements from a previous output queue and adds them to the output after processing is complete.

0
source

Source: https://habr.com/ru/post/1783876/


All Articles