Multithreading and DataSet, DataTable, DataRow

T

Thomas Gasser

Hello,

if you have defined a DataSet in the HttpApplicationState which is
shared by all current users ...

what I have to do, to make the Dataset, DataTables and DataRows
thread-safe?

Following my assumptions:

1) If I change a Row:
lock (datarow)
{
datarow["xy"] = value;
}

2) If I add Rows
lock (datatable)
{
datatable.Rows.Add(..)
}

3) If I use the Fill method
lock (datatable)
{
adpt.Fill(datatable);
// what happens with changed or currently locked datarows?
// e.g: process 1 locks row X of datatable A
thread 2 wants to lock datatable A, is process 2 waiting for process 1
to unlock row A

}

4) If I make AcceptChanges to DataTable or DataRow
lock (datatable)
{
datatable.AcceptChanges();
}

5) For datatable.Remove (lock datatable)
6) For datarow.Delete() (lock datarow)
7) For dataset.Tables.Add() (lock dataset)

8) If I do a datatable.select(...) what a have to do to make it
thread-safe?

Is this correct or completly wrong?

in your applicatoin writes on rows can only be done by one user at the
same time, reading should be possible for all users "at the same
time".

Maybe yo have some answers...

Thank u!
Thomas Gasser
 
A

Alvin Bruney [MVP]

Rather than locking every possible feature of the dataset, which in a
nutshell is what you really will end up doing, why don't you wrap the
dataset in a class and make the class access methods and properties thread
safe? You basically doing the same code but in inside a class wrapper which
is more convenient and programmatically easier to use than putting
synchronizing code all over the place.
 
T

Thomas Gasser

thank you for your comment Alvin!

thats sure! but I'm not clear about, how I can make the
Dataset/DataTables/DataRows thread-safe. are my above assumptions
correct?

Alvin Bruney said:
Rather than locking every possible feature of the dataset, which in a
nutshell is what you really will end up doing, why don't you wrap the
dataset in a class and make the class access methods and properties thread
safe? You basically doing the same code but in inside a class wrapper which
is more convenient and programmatically easier to use than putting
synchronizing code all over the place.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Thomas Gasser said:
 
A

Alvin Bruney [MVP]

yes, you would be doing the same thing but you would be calling a static
method on a class instead

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Thomas Gasser said:
thank you for your comment Alvin!

thats sure! but I'm not clear about, how I can make the
Dataset/DataTables/DataRows thread-safe. are my above assumptions
correct?

Alvin Bruney said:
Rather than locking every possible feature of the dataset, which in a
nutshell is what you really will end up doing, why don't you wrap the
dataset in a class and make the class access methods and properties
thread
safe? You basically doing the same code but in inside a class wrapper
which
is more convenient and programmatically easier to use than putting
synchronizing code all over the place.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Thomas Gasser said:
 

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