tpl-dataflow

Dataflow with splitting work to small jobs and then group again

核能气质少年 提交于 2019-12-18 23:37:17
问题 I need to do this kind of work: Get Page object from database For each page get all images and process them (IO bound, for example, upload to CDN) If all images proceeded successfully then mark Page as processed in database Since I need to control how much Pages I process in parallel I've decided to go with TPL Dataflows: ____________________________ | Data pipe | | BufferBlock<Page> | | BoundedCapacity = 1 | |____________________________| | ____________________________ | Process images | |

Why do blocks run in this order?

微笑、不失礼 提交于 2019-12-18 06:56:30
问题 This is short code sample to quickly introduce you what is my question about: using System; using System.Linq; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; namespace DataflowTest { class Program { static void Main(string[] args) { var firstBlock = new TransformBlock<int, int>(x => x, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 4 }); var secondBlock = new TransformBlock<int,string>(async x => { if (x == 12) { await Task.Delay(5000); return $"{DateTime

Why do blocks run in this order?

一世执手 提交于 2019-12-18 06:56:15
问题 This is short code sample to quickly introduce you what is my question about: using System; using System.Linq; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; namespace DataflowTest { class Program { static void Main(string[] args) { var firstBlock = new TransformBlock<int, int>(x => x, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 4 }); var secondBlock = new TransformBlock<int,string>(async x => { if (x == 12) { await Task.Delay(5000); return $"{DateTime

Where can I find a TPL dataflow version for 4.0?

走远了吗. 提交于 2019-12-17 09:48:09
问题 I am looking for the .NET 4.0 version of the TPL dataflow library. The Nuget package has a 4.0 version of the library, but it seems to target .NET 4.5. I found various references to a 4.0 version, like in this forum: http://social.msdn.microsoft.com/Forums/en-US/tpldataflow/thread/6206c714-6dee-4d17-a880-26d0c137a167 But the link mentioned just redirects me to the Nuget page of the library. Does anyone know where I can find a working version that targets .NET 4.0? 回答1: I wrote Steve from the

How to construct a TransformManyBlock with a delegate

怎甘沉沦 提交于 2019-12-13 13:20:10
问题 I'm new to C# TPL and DataFlow and I'm struggling to work out how to implement the TPL DataFlow TransformManyBlock . I'm translating some other code into DataFlow. My (simplified) original code was something like this: private IEnumerable<byte[]> ExtractFromByteStream(Byte[] byteStream) { yield return byteStream; // Plus operations on the array } And in another method I would call it like this: foreach (byte[] myByteArray in ExtractFromByteStream(byteStream)) { // Do stuff with myByteArray }

Contentious paralleled work between two collections of objects

大憨熊 提交于 2019-12-13 02:46:05
问题 I am trying to simulate work between two collections asynchronously and in parallel, I have a ConcurrentQueue of customers and a collection of workers. I need the workers to take a Customer from the queue perform work on the customer and once done take another customer right away. I decided I'd use an event-based paradigm where the collection of workers would perform an action on a customer; who holds an event handler that fires off when the customer is done; which would hopefully fire off

TPL Dataflow Consumer to Process Multiple Items at a time

柔情痞子 提交于 2019-12-13 01:29:35
问题 I have a requirement to iterate through a large list and for each item call a web service to get some data. However, I want to throttle the number of requests to the WS to say no more than 5 concurrent requests executing at any one time. All calls to the WS are made using async/await . I am using the TPL dataflow BufferBlock with a BoundedCapacity of 5. Everything is working properly but what I am noticing is that the consumer, which awaits the WS call, blocks the queue until its finished

How do I signal completion of my dataflow?

萝らか妹 提交于 2019-12-12 14:25:31
问题 I've got a class the implements a dataflow composed of 3 steps using TPL Dataflow. In the constructor I create the steps as TransformBlocks and link them up using LinkTo with DataflowLinkOptions.PropagateCompletion set to true. The class exposes a single method which kicks of the workflow by calling SendAsync on the 1st step. The method returns the "Completion" property of the final step of the workflow. At the moment the steps in the workflow appear to execute as expected but final step

How do I arrange flow control in TPL Dataflows?

£可爱£侵袭症+ 提交于 2019-12-12 13:21:51
问题 I'm trying to get my head around controlling dataflow in TPL Dataflow. I have a very fast producer, and a very slow consumer. (My real code is more complex, but none the less, this is a pretty good model and it reproduces the problem.) When I run it, the code starts drinking memory like it's going out of style--and the output queue on the producer fills up as fast as it can. What I'd really prefer to see is the Producer stop running for a while, until the Consumer has a chance to ask for it.

How to wait until item goes through pipeline?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 10:54:29
问题 So, I'm trying to wrap my head around Microsoft's Dataflow library. I've built a very simple pipeline consisting of just two blocks: var start = new TransformBlock<Foo, Bar>(); var end = new ActionBlock<Bar>(); start.LinkTo(end); Now I can asynchronously process Foo instances by calling: start.SendAsync(new Foo()); What I do not understand is how to do the processing synchronously, when needed. I thought that waiting on SendAsync would be enough: start.SendAsync(new Foo()).Wait(); But