문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top