none
multhithread updates to DataTable RRS feed

  • Question

  • Since DataTable is not ThreadSafe, what is the recommended approach to use DataTable in Parallel.ForEach loop.  With Synchronization in ForEach loop,  i am not getting any performance improvement of Parallelism.

    Regards


    singhhome
    Thursday, August 12, 2010 5:36 PM

Answers

  • Correct, that tends to decimate performance!

    You need to batch the updates.  There are a number of techniques.  Here is one:

    Put the data in a "temporary" DataSet.  Surround all access (read or write) to this DataSet with a lock.  Put a Timer control in your UI to periodically acquire the lock and, while holding the lock, move the changes out of the "temporary" DataSet into your real DataSet.  (The DataSet.Merge method followed by DataSet.Clear might suffice, depending on how simple your needs are.)

     

    Thursday, August 12, 2010 11:15 PM

All replies

  • Correct, that tends to decimate performance!

    You need to batch the updates.  There are a number of techniques.  Here is one:

    Put the data in a "temporary" DataSet.  Surround all access (read or write) to this DataSet with a lock.  Put a Timer control in your UI to periodically acquire the lock and, while holding the lock, move the changes out of the "temporary" DataSet into your real DataSet.  (The DataSet.Merge method followed by DataSet.Clear might suffice, depending on how simple your needs are.)

     

    Thursday, August 12, 2010 11:15 PM
  • Hi,

     

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, August 18, 2010 1:19 AM
    Moderator