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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:35:20+00:00 2026-06-05T09:35:20+00:00

I have a database table that contains some records to be processed. The table

  • 0

I have a database table that contains some records to be processed. The table has a flag column that represents the following status values. 1 – ready to be processed, 2- successfully processed, 3- processing failed.

The .net code (repeating process – console/service) will grab a list of records that are ready to be processed, and loop through them and attempt to process them (Not very lengthy), update status based on success or failure.

To have better performance, I want to enable multithreading for this process. I’m thinking to spawn say 6 threads, each threads grabbing a subset.

Obviously I want to avoid having different threads process the same records. I dont want to have a “Being processed” flag in the database to handle the case where the thread crashes leaving the record hanging.

The only way I see doing this is to grab the complete list of available records and assigning a group (maybe ids) to each thread. If an individual thread fails, its unprocessed records will be picked up next time the process runs.

Is there any other alternatives to dividing the groups prior to assigning them to threads?

  • 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-05T09:35:22+00:00Added an answer on June 5, 2026 at 9:35 am

    The most straightforward way to implement this requirement is to use the Task Parallel Library’s

    Parallel.ForEach (or Parallel.For).

    Allow it to manage individual worker threads.

    From experience, I would recommend the following:

    • Have an additional status “Processing”
    • Have a column in the database that indicates when a record was picked up for processing and a cleanup task / process that runs periodically looking for records that have been “Processing” for far too long (reset the status to “ready for processing).
    • Even though you don’t want it, “being processed” will be essential to crash recovery scenarios (unless you can tolerate the same record being processed twice).

    Alternatively

    Consider using a transactional queue (MSMQ or Rabbit MQ come to mind). They are optimized for this very problem.

    That would be my clear choice, having done both at massive scale.

    Optimizing

    If it takes a non-trivial amount of time to retrieve data from the database, you can consider a Producer/Consumer pattern, which is quite straightforward to implement with a BlockingCollection. That pattern allows one thread (producer) to populate a queue with DB records to be processed, and multiple other threads (consumers) to process items off of that queue.

    A New Alternative

    Given that several processing steps touch the record before it is considered complete, have a look at Windows Workflow Foundation as a possible alternative.

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

Sidebar

Related Questions

I have some records that I need to store in a database table and
I have a database table TravelRequest that contains, amongst other things, the fields SignOffName
I'm trying to normalize a mysql database.... I currently have a table that contains
I have a database table that has a Unique Key constraint defined to avoid
I have some code to update a database table that looks like try {
I have a table in an Oracle database that contains actions performed by users
I have a database table that contains names with accented characters. Like ä and
I have a SQLite database in Android with a table that contains longitude, latitude
Consider we have a database that has a table, which is a record of
I have a database table that essentially contains different types of things. I'll use

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.