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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:55:36+00:00 2026-05-29T23:55:36+00:00

when used as follows Parallel.ForEach(DataTable.AsEnumerable(), dr => { string str = dr[field1].ToString(); //…. other

  • 0

when used as follows

Parallel.ForEach(DataTable.AsEnumerable(), dr => {

    string str = dr["field1"].ToString();
     //.... other stuff
    dr["f1"] = o.A;
    dr["f2"] = o.B;
    dr["f3"] = o.C;

});

where each thread works on its own datarow

I would assume not but but there’s this saying about assumptions….

  • 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-29T23:55:38+00:00Added an answer on May 29, 2026 at 11:55 pm

    The documentation of the DataRow class definitively states that

    This type is safe for multithreaded read operations. You must
    synchronize any write operations.

    Can’t get any more specific than that.

    In any case, parallel writing to a Datatable is probably not going to scale well. Scalability suffers when you have multiple threads accessing shared state and a single datatable is quite obviously shared state. What’s more, unless you work with NUMA hardware your CPU cores will contend for access to the same memory bus.

    A much better solution is to return any results from the parallel processing (the “other stuff” ) in a separate structure (e.g. one of the concurrent collections) and apply the changes from a single thread when the loop finishes.

    Another option is to use PLINQ to calculate the results and and iterate over them with a simple foreach to apply the changes back to the DataTable.

    An even better solution would be to discard the original datatable entirely and return a new object that contains the fields you require. Unless your code requires the result to be a DataTable, you could simply return the results as an IEnumerable

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

Sidebar

Related Questions

They could be used as follows: FieldInfo field = fieldof(string.Empty); MethodInfo method1 = methodof(int.ToString);
I have used an expression for validating a positive number as follows: ^\d*\.{0,1}\d+$ when
Oracle FAQ defines temp table space as follows: Temporary tablespaces are used to manage
Scroll.js is used for #bird block, which follows the page scrolling. The main problem
I've got a simple table that is used for an inbox as follows: <table
If I have a template as follows, which is used to create a button:
I use the PHP library for Facebook Connect. The library is used as follows:
In Scheme, the term predicate is used as follows : A predicate is a
On a html page the doctype I've used is as follows (for a mobile
I used the code as follows to show up facebook avatar to ImageView @Override

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.