tpl-dataflow

TPL Dataflow, alternative to JoinBlock limitations?

吃可爱长大的小学妹 提交于 2019-12-10 16:33:23
问题 I look for an alternative to JoinBlock which can be linked to by n-TransformBlocks and join/merge messages of all TransformBlock source blocks together in order to pass a collection of such on to another data flow block. JoinBlock does the job fine but it is limited to hooking up to 3 source blocks. It also suffers from quite a number inefficiencies (very slow to join even value types (ints) of 2 source blocks). Is there a way to have Tasks returned from the TransformBlocks and wait until all

Sorting buffered Observables

只愿长相守 提交于 2019-12-10 07:00:05
问题 I've got a stream of tokens that are produced very quickly and a processer that is relatively slow. The tokens are of three sub-types and I would prefer them to processed by their priority. So, I would like the tokens to be buffered after they've been produced and are waiting to be processed and have that buffer sorted by priority. Here're my classes: public enum Priority { High = 3, Medium = 2, Low = 1 } public class Base : IComparable<Base> { public int Id { get; set; } public int CompareTo

Alternate to Dataflow BroadcastBlock with guaranteed delivery

孤者浪人 提交于 2019-12-09 03:13:59
问题 I need to have some kind of object that acts like a BroadcastBlock, but with guaranteed delivery. So i used an answer from this question. But i don't really clearly understand the execution flow here. I have a console app. Here is my code: static void Main(string[] args) { ExecutionDataflowBlockOptions execopt = new ExecutionDataflowBlockOptions { BoundedCapacity = 5 }; List<ActionBlock<int>> blocks = new List<ActionBlock<int>>(); for (int i = 0; i <= 10; i++) blocks.Add(new ActionBlock<int>

TPL Data Flow Thread Local Data

≡放荡痞女 提交于 2019-12-08 13:17:16
问题 Is there a good way to pass thread local data into an ActionBlock, such that if you specify MaxDegreeOfParallelization in its DataFlowExecutionOptions to be > 1, then each task that executes the action will have its own thread local data? Here is some of my code that will perhaps clarify what I want to do: var options = new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = 12 }; ActionBlock<int> actionBlock = new ActionBlock<int>(PerformAction, options); List<int> resultsList = new

TPL Dataflow local storage or something like it

折月煮酒 提交于 2019-12-08 08:32:31
问题 What I'm trying to accomplish is I have a action block with MaxDegreeOfParallelism = 4 . I want to create one local instance of a session object I have for each parallel path, So I want to total of 4 session objects. If this was threads I would creating something like: ThreadLocal<Session> sessionPerThread = new ThreadLocal<Session>(() => new Session()); I know blocks are not threads so I'm looking for something similar but for blocks. Any way to create this? This block is in a service and

Completing a TPL dataflow chain

岁酱吖の 提交于 2019-12-08 03:54:58
问题 Given this code: s_Batch = new BatchBlock<PerformanceRecord>(500); s_Action = new ActionBlock<PerformanceRecord[]>(a => SendToDatabase(a)); s_Batch.LinkTo(s_Action); When I'm done do I need to call Complete() on each block? Or will completing s_Batch trigger a complete in the blocks linked to it? 回答1: As your code stands now, you need to call Complete on all blocks individually: s_Batch.Complete(); await s_Batch.Completion; s_Action.Complete(); await s_Action.Completion; You could however use

BufferBlock and ActionBlock with BoundedCapacity does not use max DOP

有些话、适合烂在心里 提交于 2019-12-07 05:29:56
问题 I have this code: var data = new BufferBlock<int>(new DataflowBlockOptions { BoundedCapacity = 1 }); var action = new ActionBlock<int>(async id => { Console.WriteLine("[{0:T}] #{1}: Start", DateTime.Now, id); await Task.Delay(1000); Console.WriteLine("[{0:T}] #{1}: End", DateTime.Now, id); }, new ExecutionDataflowBlockOptions { BoundedCapacity = 1, MaxDegreeOfParallelism = -1 }); data.LinkTo(action, new DataflowLinkOptions { PropagateCompletion = true }); for (var id = 1; id <= 3; id++) {

What is difference between System.Threading.Tasks.Dataflow and Microsoft.Tpl.Dataflow

和自甴很熟 提交于 2019-12-06 18:33:16
问题 There are 2 different official TPL Dataflow nuget package. I am confused to choose which one i should to use. As far as i understand System.Threading.Tasks.Dataflow version is tiny bit newer than other and it seems System.Threading.Tasks.Dataflow is targeted latest versions of .net. Anyone can explain differences between of those ? 回答1: Microsoft.Tpl.Dataflow was first released as a component separate from the BCL as part of .net 4.5 - here is a blog post announcing the release System

Apparent BufferBlock.Post/Receive/ReceiveAsync race/bug

血红的双手。 提交于 2019-12-06 17:13:29
问题 cross-posted to http://social.msdn.microsoft.com/Forums/en-US/tpldataflow/thread/89b3f71d-3777-4fad-9c11-50d8dc81a4a9 I know... I'm not really using TplDataflow to its maximum potential. ATM I'm simply using BufferBlock as a safe queue for message passing, where producer and consumer are running at different rates. I'm seeing some strange behaviour that leaves me stumped as to how to proceed. private BufferBlock<object> messageQueue = new BufferBlock<object>(); public void Send(object message

Get batches of messages as available

ε祈祈猫儿з 提交于 2019-12-06 16:34:56
I am trying to achieve the following behaviour using the Task Parallel Library: As messages arrive I would like to process them sequentially but in groups. So when the first message arrives it should be processed immediately. If 2 messages come in while the first is being processed then they should be processed in a group of 2. I can almost get what I want using a BatchBlock linked to an ActionBlock var batchBlock = new BatchBlock<int>(100); var actionBlock = new ActionBlock<int[]>(list => { // do work // now trigger batchBlock.TriggerBatch(); }); batchBlock.LinkTo(actionBlock); The problem