Where to Lock when updating a DataTable

P

paul

Hi,

I have an C# app which uses a Dataset which contains multiple
DataTables as an in memory database. (Currently the dataset is not
connected to a database.)

The app is multi threaded and adds/update rows in the various tables.
Currently I lock the Dataset on each modification - but am I locking at
the right (most efficent) level? Could I just lock at the DataTable or
even just the row? or can I do without locks?

TIA

swin
 
M

Miha Markic [MVP C#]

Hi Paul,

I would lock at DataTable level as row update might affect internals (index,
etc.).
Note that I am not 100% sure whether this is enough.
 
P

paul

OK thanks.

Paul
Hi Paul,

I would lock at DataTable level as row update might affect internals (index,
etc.).
Note that I am not 100% sure whether this is enough.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Hi,

I have an C# app which uses a Dataset which contains multiple
DataTables as an in memory database. (Currently the dataset is not
connected to a database.)

The app is multi threaded and adds/update rows in the various tables.
Currently I lock the Dataset on each modification - but am I locking at
the right (most efficent) level? Could I just lock at the DataTable or
even just the row? or can I do without locks?

TIA

swin
 
M

Miha Markic [MVP C#]

And you might also consider using ReaderWriterLock as your locking mechanism
in case you have many reads and few writes.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

OK thanks.

Paul
Hi Paul,

I would lock at DataTable level as row update might affect internals
(index,
etc.).
Note that I am not 100% sure whether this is enough.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Hi,

I have an C# app which uses a Dataset which contains multiple
DataTables as an in memory database. (Currently the dataset is not
connected to a database.)

The app is multi threaded and adds/update rows in the various tables.
Currently I lock the Dataset on each modification - but am I locking at
the right (most efficent) level? Could I just lock at the DataTable or
even just the row? or can I do without locks?

TIA

swin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top