There is a continuous data flow from a source;
I want to keep a certain amount of the most current data from that flow. If I use BufferBlock
and BoundedCapacity = 200
; It'll keep the first 200 data from flow, not the N latest 200. Basically, I want to build a FIFO buffer, The buffer will drop the previous data if there is new data coming and the buffer is full.
I know the behavior of the BroadCastBlock
but it keeps just a single message. I would like to have the same behavior but keeping more messages instead of one. I want to store the last few items sent. I tried to use BroadCastBlock
with DataflowBlockOptions() { BoundedCapacity = 250 }
but it didn't work.
TPLBlockOptions = new DataflowBlockOptions() { BoundedCapacity = 200 };
TPLBlock = new BroadcastBlock<Data>(z => z, TPLBlockOptions);
while(IsDataFlowActive)
{
await TPLBlock.SendAsync(rawData);
}
For the consumer part, I don't know when to use the data. But the data in the Buffer must be up to date.
Can I do that with the TPL library? I saw and read this post and its answers. If this is a duplicate of it, I'll delete this post. Any advice would be appreciated.