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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:19:51+00:00 2026-06-13T00:19:51+00:00

Batch read text from file or SQL parse the text into words load the

  • 0

Batch

  1. read text from file or SQL
  2. parse the text into words
  3. load the words into SQL

Today
.NET 4.0
Step 1 is very fast.
Steps 2 and 3 are about the same length (avg 0.1 second) for the same size file.
On step 3 insert using BackGroundWorker and wait for last to complete.
Everything else is on the main thread.

On a big load will do this several million times.

Need step 3 to be serial and in the same order as 1.
This is to keep the SQL table PK index from fracturing.
Tried step 3 in parallel and fracturing the index killed it.
This data is fed sorted by the PK.
Other indexes are dropped at the start of the load then rebuilt at the end of the load.

Where this process is not effective is when the size of text changes.
And the size of the text from file to file does change drastically.
What I would like is to queue 1 and 2 so 3 is kept as busy as possible.

Need step 3 to dequeue the files in order they were enqueued in 1 (even if it waits).

Need a maximum queue size for memory management (like 4-10).

Would like to have step 2 parallel with up to 4 concurrent.

Moving to .NET 4.5.

Asking for general guidance on how to implement this?

I am learning that this is a producer consumer pattern.
If this is not a producer consumer pattern please let me know so I can change the title.

  • 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-13T00:19:52+00:00Added an answer on June 13, 2026 at 12:19 am

    I think TPL Dataflow would be a good way to do this:

    For step 2, you would use a TransformBlock with MaxDegreeOfParallelism set to 4 and BoundedCapacity also set to 4, so that its queues are empty when working. It will produce the items in the same order as they came in, you don’t have to do anything special for that. For step 3, use an ActionBlock, with BoundedCapacity set to your limit. Then link the two together and start sending items to the TransformBlock, ideally using something like await stepTwoBlock.SendAsync(…), to asynchronously wait if the queue is full.

    In code, it would look something like:

    async Task ProcessData()
    {
        var stepTwoBlock = new TransformBlock<OriginalText, ParsedText>(
            text => Parse(text),
            new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 4,
                BoundedCapacity = 4
            });
        var stepThreeBlock = new ActionBlock<ParsedText>(
            text => LoadIntoDatabase(text),
            new ExecutionDataflowBlockOptions { BoundedCapacity = 10 });
        stepTwoBlock.LinkTo(
            stepThreeBlock, new DataflowLinkOptions { PropagateCompletion = true });
    
        // this is step one:
        foreach (var id in IdsToProcess)
        {
            OriginalText text = ReadText(id);
            await stepTwoBlock.SendAsync(text);
        }
    
        stepTwoBlock.Complete();
        await stepThreeBlock.Completion;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read each line from a text file using batch. The lines
How you can read a file (text or binary) from a batch file? There
I want to write a batch file to read an input text file, extract
I want to read entire content of a text file in a batch file.
How can I read the first line from a text file using a Windows
Part 1 I'm trying to read a text file and then copy into another
Can anyone tell me using batch file in windows ...how to read from a
I have a batch file running which spits out a text/html file. The batch
We have a text file that lists a bunch of paths, and a batch
I am struggling to write a batch script which can read a CSV file

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.