Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to lock a multi-dimensional DataTable for multi-Threading, currently I am using the following code but it does not seem to work, any help would be greatly appreciated.

Can I lock the DataTable the following way, if not can you please give an example,
thanks in advance.

Michael

What I have tried:

lock (MyDataSet[n, x].MyDataTable)
{
MyDataSet[n, x].MyDataTable[record].Name = "John";
}
Posted
Updated 23-Feb-16 20:27pm
Comments
Sergey Alexandrovich Kryukov 24-Feb-16 1:06am    
To start with, there is no such thing as "multi-dimensional datatable". Perhaps your data model is used to describe something multi-dimensional, but it makes no difference, and totally unrelated to threading. What you are trying to do, doesn't really make sense.
—SA

1 solution

Instead to lock the table lock the SyncRoot[^] of the rows...
C#
lock (MyDataSet[n, x].MyDataTable.Rows.SyncRoot)
{
  MyDataSet[n, x].MyDataTable.Rows[record].Name = "John";
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900