tpl-dataflow

Using AsObservable to observe TPL Dataflow blocks without consuming messages

夙愿已清 提交于 2020-07-08 09:40:37
问题 I have a chain of TPL Dataflow blocks and would like to observe progress somewhere inside the system. I am aware that I could just jam a TransformBlock into the mesh where I want to observe, get it to post to a progress updater of some variety and then return the message unchanged to the next block. I don't love this solution as the block would be purely there for its side-effect and I would also have to change the block linking logic wherever I want to observe. So I wondered if I could use

TPL DataFlow propagate completion only when all data has been processed

℡╲_俬逩灬. 提交于 2020-06-29 05:26:14
问题 I have a producer sending data to a BufferBlock and when all data has been read from the source, it calls Complete() . The default behaviour is that when the completion is called, even if the buffer still has messages, it propagates the completion down the pipeline. Is there a wait to tell a block: Propagate the completion only once your buffer is empty? When the completion occurs, I get an exception on Receive : InvalidOperationException: 'The source completed without providing data to

TPL Dataflow: Why does EnsureOrdered = false destroy parallelism for this TransformManyBlock?

元气小坏坏 提交于 2020-06-27 13:17:15
问题 I'm working on a TPL Dataflow pipeline and noticed some strange behaviour related to ordering/parallelism in TransformManyBlock s (might apply to other blocks as well). Here is my code to reproduce (.NET 4.7.2, TPL Dataflow 4.9.0): class Program { static void Main(string[] args) { var sourceBlock = new TransformManyBlock<int, Tuple<int, int>>(i => Source(i), new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 4, EnsureOrdered = false }); var targetBlock = new ActionBlock<Tuple<int,

Understanding TPL Dataflow Degree of Parallelism ordering

这一生的挚爱 提交于 2020-06-27 08:49:10
问题 I was reading Dataflow (Task Parallel Library), and there is a portion which says: When you specify a maximum degree of parallelism that is larger than 1, multiple messages are processed simultaneously, and therefore, messages might not be processed in the order in which they are received. The order in which the messages are output from the block will, however, be correctly ordered. What does it means? Example, I set my action block with degree of parallelism = 5: testActionBlock = new

How to call TriggerBatch automagically after a timeout if the number of queued items is less than the BatchSize?

旧巷老猫 提交于 2020-06-24 04:13:33
问题 Using Dataflow CTP (in the TPL) Is there a way to call BatchBlock.TriggerBatch automatically if the number of currently queued or postponed items is less than the BatchSize, after a timeout ? And better: this timeout should be reset to 0 each time the block receives a new item. 回答1: Yes, you can accomplish this rather elegantly by chaining together blocks. In this case you want to setup a TransformBlock which you link "before" the BatchBlock. That would look something like this: Timer

How to call TriggerBatch automagically after a timeout if the number of queued items is less than the BatchSize?

自作多情 提交于 2020-06-24 04:12:09
问题 Using Dataflow CTP (in the TPL) Is there a way to call BatchBlock.TriggerBatch automatically if the number of currently queued or postponed items is less than the BatchSize, after a timeout ? And better: this timeout should be reset to 0 each time the block receives a new item. 回答1: Yes, you can accomplish this rather elegantly by chaining together blocks. In this case you want to setup a TransformBlock which you link "before" the BatchBlock. That would look something like this: Timer

How to force an ActionBlock to complete fast

痴心易碎 提交于 2020-06-01 07:16:07
问题 According to the documentation: A dataflow block is considered completed when it is not currently processing a message and when it has guaranteed that it will not process any more messages. This behavior is not ideal in my case. I want to be able to cancel the job at any time, but the processing of each individual action takes a long time. So when I cancel the token, the effect is not immediate. I must wait for the currently processed item to complete. I have no way to cancel the actions

Can an ActionBlock contain a state?

蓝咒 提交于 2020-03-24 14:17:36
问题 I'm writing an application that is using TPL dataflow. I'm trying to configure an action block to write to a database. However, I need this action block to perform an initialization step on the first message it receives (note that I must wait for the first message and cannot perform the initialization during the action block creation). Because of this, my action block needs to maintain some sort of state that indicates if its already received the first message. Is it possible for an

TPL Dataflow never completes when using a predicate

别来无恙 提交于 2020-02-04 14:29:55
问题 I have the following TPL Dataflow that never completes when using a predicate to filter the items passed from the TransformBlock to the ActionBlock. If the predicate returns false for any of the items, then the dataflow hangs. Please can someone offer some insight as to what's happening and how to resolve this? // define blocks var getBlock = new TransformBlock<int, int>(i => { Console.WriteLine($"getBlock: {i}"); return ++i; }); var writeBlock = new ActionBlock<int>(i => { Console.WriteLine(

TPL Dataflow never completes when using a predicate

北城余情 提交于 2020-02-04 14:25:28
问题 I have the following TPL Dataflow that never completes when using a predicate to filter the items passed from the TransformBlock to the ActionBlock. If the predicate returns false for any of the items, then the dataflow hangs. Please can someone offer some insight as to what's happening and how to resolve this? // define blocks var getBlock = new TransformBlock<int, int>(i => { Console.WriteLine($"getBlock: {i}"); return ++i; }); var writeBlock = new ActionBlock<int>(i => { Console.WriteLine(