tpl-dataflow

BufferBlock deadlock with OutputAvailableAsync after TryReceiveAll

不问归期 提交于 2019-12-03 04:20:58
问题 While working on an answer to this question, I wrote this snippet: var buffer = new BufferBlock<object>(); var producer = Task.Run(async () => { while (true) { await Task.Delay(TimeSpan.FromMilliseconds(100)); buffer.Post(null); Console.WriteLine("Post " + buffer.Count); } }); var consumer = Task.Run(async () => { while (await buffer.OutputAvailableAsync()) { IList<object> items; buffer.TryReceiveAll(out items); Console.WriteLine("TryReceiveAll " + buffer.Count); } }); await Task.WhenAll

Benefits of using BufferBlock<T> in dataflow networks

淺唱寂寞╮ 提交于 2019-12-02 20:39:37
I was wondering if there are benefits associated with using a BufferBlock linked to one or many ActionBlocks, other than throttling (using BoundedCapacity), instead of just posting directly to ActionBlock(s) (as long as throttling is not required). If all you want to do is to forward items from one block to several others, you don't need BufferBlock . But there are certainly cases where it is useful. For example, if you have a complex dataflow network, you might want to build it from smaller sub-networks, each one created in its own method. And to do this, you need some way to represent a

TPL Dataflow, guarantee completion only when ALL source data blocks completed

早过忘川 提交于 2019-12-02 20:28:42
How can I re-write the code that the code completes when BOTH transformblocks completed? I thought completion means that it is marked complete AND the " out queue" is empty? public Test() { broadCastBlock = new BroadcastBlock<int>(i => { return i; }); transformBlock1 = new TransformBlock<int, string>(i => { Console.WriteLine("1 input count: " + transformBlock1.InputCount); Thread.Sleep(50); return ("1_" + i); }); transformBlock2 = new TransformBlock<int, string>(i => { Console.WriteLine("2 input count: " + transformBlock1.InputCount); Thread.Sleep(20); return ("2_" + i); }); processorBlock =

BufferBlock deadlock with OutputAvailableAsync after TryReceiveAll

我是研究僧i 提交于 2019-12-02 17:36:37
While working on an answer to this question , I wrote this snippet: var buffer = new BufferBlock<object>(); var producer = Task.Run(async () => { while (true) { await Task.Delay(TimeSpan.FromMilliseconds(100)); buffer.Post(null); Console.WriteLine("Post " + buffer.Count); } }); var consumer = Task.Run(async () => { while (await buffer.OutputAvailableAsync()) { IList<object> items; buffer.TryReceiveAll(out items); Console.WriteLine("TryReceiveAll " + buffer.Count); } }); await Task.WhenAll(consumer, producer); The producer should post items to the buffer every 100 ms and the consumer should

BroadcastCopyBlock for TPL Dataflow with guaranteed delivery

若如初见. 提交于 2019-12-02 00:35:56
I would be glad for some input on the following implementation of a BroadcastCopyBlock in TPL Dataflow, which copies a received message to all consumers, that registered to the BroadcastCopyBlock and guarantees delivery to all consumers, which are linked to the block at the time it receives the message. (Unlike the BroadcastBlock which does not guarntee delivery of messages, if the next one comes in, before the former message has been delivered to all consumers). My main concern is the reserving of messages and releasing of reservations. What would happen, if a receiving block decides to not

Task Dataflow, can a data block be changed from completion state?

时光怂恿深爱的人放手 提交于 2019-12-01 06:06:51
I would like to know whether it is possible to change the completion state of data blocks? For example, I marked a var block = new BufferBlock<int>(); data block complete with block.Complete() . The block is linked to other data blocks. I would like to know whether I can make block run again by changing its completion state back to its original !complete state. If that is not possible how could I perform multiple runs, including completion, without having to a) de-link all blocks, b) re-instantiate all blocks,and c) re-link all blocks again? Any ideas which may ease the task of running data

Task Dataflow, can a data block be changed from completion state?

孤人 提交于 2019-12-01 03:57:09
问题 I would like to know whether it is possible to change the completion state of data blocks? For example, I marked a var block = new BufferBlock<int>(); data block complete with block.Complete() . The block is linked to other data blocks. I would like to know whether I can make block run again by changing its completion state back to its original !complete state. If that is not possible how could I perform multiple runs, including completion, without having to a) de-link all blocks, b) re

Problems with references to TPL Dataflow and TPL in VS 2012 RC

那年仲夏 提交于 2019-11-30 22:12:30
问题 I just upgraded Visual Studio 11 Beta to the new Visual Studio 2012 RC and have problems referencing TPL Dataflow. First, I tried to reference Dataflow as I did previously, by adding a reference from the framework. But when I try to do that, I get an error box: A reference to 'System.Threading.Tasks.Dataflow' could not be added. and then the whole Visual Studio freezes. After reading MEF and TPL Dataflow NuGet Packages for .NET Framework 4.5 RC, I assumed the version of Dataflow that showed

BatchBlock produces batch with elements sent after TriggerBatch()

别来无恙 提交于 2019-11-30 19:08:55
问题 I have a Dataflow pipeline consisting of several blocks. When elements are flowing through my processing pipeline, I want to group them by field A . To do this I have a BatchBlock with high BoundedCapacity . In it I store my elements until I decide that they should be released. So I invoke TriggerBatch() method. private void Forward(TStronglyTyped data) { if (ShouldCreateNewGroup(data)) { GroupingBlock.TriggerBatch(); } GroupingBlock.SendAsync(data).Wait(SendTimeout); } This is how it looks.

TPL Dataflow: Bounded capacity and waiting for completion

限于喜欢 提交于 2019-11-30 16:04:21
问题 Below I have replicated a real life scenario as a LINQPad script for the sake of simplicity: var total = 1 * 1000 * 1000; var cts = new CancellationTokenSource(); var threads = Environment.ProcessorCount; int capacity = 10; var edbOptions = new ExecutionDataflowBlockOptions{BoundedCapacity = capacity, CancellationToken = cts.Token, MaxDegreeOfParallelism = threads}; var dbOptions = new DataflowBlockOptions {BoundedCapacity = capacity, CancellationToken = cts.Token}; var gdbOptions = new