Thread safety in disconnected ADO.NET dataset

N

Navin Mishra

Hi,

I've multiple related data tables in a disconnected dataset which could be
accessed by mutltiple threads to read and write data. The documentation says
that dataset and datatable are thread safe to read in multithreaded
environment but one needs to lock them to update. Questions:

1) Is it not required to synchronize when searching data using Find, Select
and GetChildRows methods ?
2) Is it not required to synchronize when reading data using from returned
rows from above ?
3) When updating a row in a datatable, is it required to lock only datatable
or the whole dataset ?
4) Is ReaderWriterLock recommended in this disconnected scenario or using
Monitor/lock is "good enough" ?

Thanks in advance and regards

Navin
 
T

Truong Hong Thi

Hi Navin,

Here is my opinion:

1) Is it not required to synchronize when searching data using Find,
Select
and GetChildRows methods?
No.
2) Is it not required to synchronize when reading data using from
returned
rows from above ?
No. I assume that you only need to read data of the rows returned, and
does not need to manipulate the Array object containing those rows.
3) When updating a row in a datatable, is it required to lock only
datatable
or the whole dataset ?
It does not matter. Just lock on a same object. Prefer a private one.
You seem to misunderstand a bit. Locking is to ensure no other thread
can acquire a lock on the same object at the same time - no matter what
the object is as long as it is a reference-type one.
4) Is ReaderWriterLock recommended in this disconnected scenario or
using
Monitor/lock is "good enough" ?
Monitor/lock is "good enough" in this case.

Regards,
Thi
 

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