Pregunta

Let's assume i have a simple ActionBlock<int>

var actionBlock = new ActionBlock<int>(_ => Console.WriteLine(_));

I can specify a bounded capacity to enable buffering:

var actionBlock = new ActionBlock<int>(
    _ => Console.WriteLine(_),
    new ExecutionDataflowBlockOptions
    { 
        BoundedCapacity = 1000
    });

Is it better to create a BufferBlock<T> and link it to the actionBlock, is it the same, Or is it redundant?

¿Fue útil?

Solución

If you just added the bounded BufferBlock before your ActionBlock, then that wouldn't work correctly, because the ActionBlock would still be unbounded. So, items would keep accumulating in the ActionBlock's input queue, achieving nothing.

If you added the bounded BufferBlock and also set BoundedCapacity of the ActionBlock to 1, then that would work (plus minus 1).

Doing it this way doesn't give you much (except adding some small overhead), so generally speaking, you should just set BoundedCapacity of the ActionBlock. But there might be some cases where the combination of a bounded BufferBlock and an ActionBlock bounded to 1 might make sense. For example, when you want to set the capacity only after creating the ActionBlock.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top