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 8635683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:02:29+00:00 2026-06-12T10:02:29+00:00

In my application I have three classes, Extractor , Transformer and Loader , which

  • 0

In my application I have three classes, Extractor, Transformer and Loader, which are coordinated by a fourth class, Coordinator. Extractor, Transformer and Loader are very simple and do the following:

Extractor

Exposes a member called Results of type IEnumerable<string>, for example by reading from a text file. Extraction should be synchronous.

Transformer

Exposes a member called Transform which accepts a string and transforms it to another string via some process which is expected to be time-consuming (use parallel processing here).

Loader

Exposes a member called Load which accepts a string and loads it into some final form (e.g. another text file). Loading should be synchronous.

The Coordinator classes coordinates the three operations. The transformation process should be done in parallel, and then push the results to a queue which is read by the loader. Coordinator‘s Run() method looks like this:

Extractor extractor = new Extractor();
Transformer transformer = new Transformer();
Loader loader = new Loader();

ConcurrentQueue<string> outputs = new ConcurrentQueue<string>();

Parallel.ForEach(extractor.Results, x => outputs.Enqueue(transformer.Transform(x)));

foreach(string output in outputs)
{
  loader.Load(output);
}

This is working well, except that ALL transformation must be finished before any loading can be done – i.e. the Parallel.ForEach() completes before the following foreach starts. I would prefer that each output is passed to the loader as soon as it is ready.

I also tried this:

Extractor extractor = new Extractor();
Transformer transformer = new Transformer();
Loader loader = new Loader();

ConcurrentQueue<string> outputs = new ConcurrentQueue<string>();

foreach (string input in extractor.Results)
{
  string input1 = input;
  Task task = Task.Factory.StartNew(
                    () => outputs.Enqueue(transformer.Transform(input1)));
}

foreach(string output in outputs)
{
  loader.Load(output);
}

But then the foreach loop at the bottom gets hit before any outputs have been added to the queue, and so it simply exits.

How do I get loading to happen as soon as results are available from the calls to transformer.Transform()?

  • 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-12T10:02:30+00:00Added an answer on June 12, 2026 at 10:02 am

    Try a BlockingCollection instead with Parallel.Invoke. In the example below, GetConsumingEnumerable (the Consumer part of the Producer-Consumer pattern) won’t finish until CompleteAdding is called so load will run until fill is completed.

    var outputs = new BlockingCollection<string>();
    
    // aka Producer
    Action fill = () => {
        Parallel.ForEach(extractor.Results, x => outputs.Add(transformer.Transform(x)));        
        outputs.CompleteAdding();
    };
    
    // aka Consumer
    Action load = () => {
       foreach(var o in outputs.GetConsumingEnumerable()) 
           loader.Load(o);
    }
    
    Parallel.Invoke(fill, load);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our application we have two or three classes which contains the entire Java
I have an application written in pure/basic Java without GUI. I have three classes
In my application, I have three collection objects which store data. The data which
I have an application which is using a set of three combo boxes. I
hi I created a view based application and I have three classes: -MyAppViewController; -Item
I have several classes in my application, all of which have a Name property
I have three classes, TImageProcessingEngine , TImage and TProcessing TImageProcessingEngine is the one which
I am creating window c# desktop application I have three columns in my datagridview
i have three java based web application app1,app2 and app3 at production. All 3
I have a three-tier Windows Forms DB application in VB.NET. I'm using VS 2005.

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.