If I'm updating a DataRow, do I lock the entire DataTable or just the DataRow?

Posted by Dan Tao on Stack Overflow See other posts from Stack Overflow or by Dan Tao
Published on 2010-04-09T13:10:55Z Indexed on 2010/04/09 13:13 UTC
Read the original article Hit count: 399

Filed under:
|
|
|
|

Suppose I'm accessing a DataTable from multiple threads. If I want to access a particular row, I suspect I need to lock that operation (I could be mistaken about this, but at least I know this way I'm safe):

// this is a strongly-typed table
OrdersRow row = null;
lock (orderTable.Rows.SyncRoot) {
    row = orderTable.FindByOrderId(myOrderId);
}

But then, if I want to update that row, should I lock the table (or rather, the table's Rows.SyncRoot object) again, or can I simply lock the row?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET