Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9211063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:12:40+00:00 2026-06-18T01:12:40+00:00

I’m processing images using TPL Dataflow. I receive a processing request, read an image

  • 0

I’m processing images using TPL Dataflow. I receive a processing request, read an image from a stream, apply several transformations, then write the resulting image to another stream:

Request -> Stream -> Image -> Image ... -> Stream

For that I use the blocks:

BufferBlock<Request>
TransformBlock<Request,Stream>
TransformBlock<Stream,Image>
TransformBlock<Image,Image>
TransformBlock<Image,Image>
...
writerBlock = new ActionBlock<Image>

The problem is the initial Request is what contains some data necessary to create the resulting Stream along with some additional info I need at that point. Do I have to pass the original Request (or some other context object) down the line to the writerBlock across all the other blocks like this:

TransformBlock<Request,Tuple<Request,Stream>>
TransformBlock<Tuple<Request,Stream>,Tuple<Request,Image>>
TransformBlock<Tuple<Request,Image>,Tuple<Request,Image>>
...

(which is ugly), or is there a way to link the first block to the last one (or, generalizing, to the ones that need the additional data)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:12:42+00:00Added an answer on June 18, 2026 at 1:12 am

    Yes, you pretty much need to do what you described, passing the additional data from every block to the next one.

    But using a couple of helper methods, you can make this much simpler:

    public static IPropagatorBlock<TInput, Tuple<TOutput, TInput>>
        CreateExtendedSource<TInput, TOutput>(Func<TInput, TOutput> transform)
    {
        return new TransformBlock<TInput, Tuple<TOutput, TInput>>(
            input => Tuple.Create(transform(input), input));
    }
    
    public static IPropagatorBlock<Tuple<TInput, TExtension>, Tuple<TOutput, TExtension>>
        CreateExtendedTransform<TInput, TOutput, TExtension>(Func<TInput, TOutput> transform)
    {
        return new TransformBlock<Tuple<TInput, TExtension>, Tuple<TOutput, TExtension>>(
            tuple => Tuple.Create(transform(tuple.Item1), tuple.Item2));
    }
    

    The signatures look daunting, but they are actually not that bad.

    Also, you might want to add overloads that pass options to the created block, or overloads that take async delegates.

    For example, if you wanted to perform some operations on a number using separate blocks, while passing the original number along the way, you could do something like:

    var source = new BufferBlock<int>();
    var divided = CreateExtendedSource<int, double>(i => i / 2.0);
    var formatted = CreateExtendedTransform<double, string, int>(d => d.ToString("0.0"));
    var writer = new ActionBlock<Tuple<string, int>>(tuple => Console.WriteLine(tuple));
    
    source.LinkTo(divided);
    divided.LinkTo(formatted);
    formatted.LinkTo(writer);
    
    for (int i = 0; i < 10; i++)
        source.Post(i);
    

    As you can see, your lambdas (except for the last one) deal only with the “current” value (int, double or string, depending on the stage of the pipeline), the “original” value (always int) is passed automatically. At any moment, you can use block created using the normal constructor to access both values (like the final ActionBlock in the example).

    (That BufferBlock isn’t actually necessary, but I added it to more closely match your design.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jsonparser to parse data and images obtained from json response. When
I am using JSon response to parse title,date content and thumbnail images and place
I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.