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

  • Home
  • SEARCH
  • 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 6822323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:38:59+00:00 2026-05-26T21:38:59+00:00

I have a data table full of summary entries and my software needs to

  • 0

I have a data table full of summary entries and my software needs to go through and reach out to a web service to get details, then record those details back to the database. Looping through the table synchronously while calling the web service and waiting for the response is too slow (there are thousands of entries) so I’d like to take the results (10 or so at a time) and thread it out so it performs 10 operations at the same time.

My experience with C# threads is limited to say the least, so what’s the best approach? Does .NET have some sort of threadsafe queue system that I can use to make sure that the results get handled properly and in order?

  • 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-05-26T21:38:59+00:00Added an answer on May 26, 2026 at 9:38 pm

    Depending on which version of the .NET Framework you have two pretty good options.

    You can use ThreadPool.QueueUserWorkItem in any version.

    int pending = table.Rows.Count;
    var finished = new ManualResetEvent(false);
    foreach (DataRow row in table.Rows)
    {
      DataRow capture = row; // Required to close over the loop variable correctly.
      ThreadPool.QueueUserWorkItem(
        (state) =>
        {
          try
          {
            ProcessDataRow(capture);
          }
          finally
          {
             if (Interlocked.Decrement(ref pending) == 0) 
             {
               finished.Set();  // Signal completion of all work items.
             }
          }
        }, null);
    }
    finished.WaitOne(); // Wait for all work items to complete.
    

    If you are using .NET Framework 4.0 you can use the Task Parallel Library.

    var tasks = new List<Task>();
    foreach (DataRow row in table.Rows)
    {
      DataRow capture = row; // Required to close over the loop variable correctly.
      tasks.Add(
        Task.Factory.StartNew(
          () =>
          {
            ProcessDataRow(capture);        
          }));
    }
    Task.WaitAll(tasks.ToArray()); // Wait for all work items to complete.
    

    There are many other reasonable ways to do this. I highlight the patterns above because they are easy and work well. In the absence of specific details I cannot say for certain that either will be a perfect match for your situation, but they should be a good starting point.

    Update:

    I had a short period of subpar cerebral activity. If you have the TPL available you could also use Parallel.ForEach as a simpler method than all of that Task hocus-pocus I mentioned above.

    Parallel.ForEach(table.Rows,
      (DataRow row) =>
      {
        ProcessDataRow(row);
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

basically i have a table full of data that needs to be processed. i
I have a database table full of some really ugly and messy data. In
I have a table full of data, where one column is full of different
I have a table full of tabular data. I need to find the index
I have a table full of tracking data for as specific course, course number
I have a table full of data called MYTABLE I used SELECT * FROM
I have a table full of data, and at the end of the row
I have a table full of data that's typically pretty manageable, but on occasion
I have a series of tables that contain data I want to full text
I have data table containing one column as FilePath. FilePath D:\New folder\link.txt D:\New folder\SharepointMigration(Work

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.