473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dataset thread: how thread safe?

Hi All
MSDN documentation explains the thread safety of the Dataset (and the underlying rows and tables) this way
"This type is safe for multithreaded read operations. You must synchronize any write operations.

Does this means that the following code is thread safe
public class Class

private Dataset1 m_ds = new Dataset1
public Class1(

public void AddEntry(string name, string description

lock(this

m_ds.LogEntries.AddLogEntriesRow( System.DateTime.Now, name, description )

public void GetEntry(int index, out string name, out string description

Dataset1.LogEntriesRow rw = m_ds.LogEntries[index]
description = rw.Description
name = rw.Description

My assumption is that datasets are not thread safe as soon as you start writting in it, so to be thread safe I would nee
public void GetEntry(int index, out string name, out string description

lock(this

Dataset1.LogEntriesRow rw = m_ds.LogEntries[index]
description = rw.Description
name = rw.Description

but maybe I misinterpret the documentation..

Thank
JPRoot
Nov 15 '05 #1
2 9712
Hi,

Yes, your understanding is correct, DataSet is designed to be the
multi-reader or single writer. It's up to the consumer of the dataset to do
synchronization if they want to support multi-thread read/write.

Does it answer your question?
Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.

Nov 15 '05 #2
Hi,

After a second look on your revised code, it does syhchronized the read and
write. however
it prevents the concurrent reading, there will always be only one read at
a time.
You may try using the ReaderWriteLock class to do locking.
For how to use the ReaderWriterLock you may refer to the documentation
below, there is also an example in it.
<ReaderWriterLock class>
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemThreadingReaderWriterLockClassTopic.asp

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steven Brown | last post by:
I'm trying to figure out how to safely use .NET events/delegates in a thread-safe class. There are a couple problems. One is that the standard "if(EventName != null) EventName(...);" call can...
1
by: Arthur Dzhelali | last post by:
I according to MSDN dataview and dataset are thread safe for read operations, but we run into this scenario. I just would like to see some comments on it. Aplication written in VB.NET it is an...
20
by: Sacha | last post by:
Consider I have a working thread like this, while (1) { if ( g_pObject ) g_pObject->DoOneStep(); } with an class hierarchie like this
3
by: [Yosi] | last post by:
I have some unreasonable issue while reading access component from other thread. I have a Form class which includes TreeView, this tree view includes some TreeNodes , lets say 2 . In my Form...
4
by: Robin Tucker | last post by:
Some thread confusion to lighten up your day: I have a worker thread and a main form. When the user clicks the Close icon in the top right of the form, my program tells the thread to "stop". ...
1
by: George | last post by:
Hi, I have a DataGridView, bounded to a DataTable which is populated/updated by a OleDbDataAdapter (with OleDbConnection) to an Access Database. (Sounds familiar to some of you ... I have...
1
by: batista | last post by:
Hello all, I have a third praty grid control...named C1grid. Im using it in one of my apps.. Now, I have bind this grid to a custom dataset class named "DataViewEx". The code of the class is...
8
by: shark | last post by:
Hi. I have DataGridView bound to my dataset through bindingsource component. My dataset is filled on separate thread. While this thread is working I receive "Cross-thread operation not valid"...
16
by: Paul Schwann | last post by:
Hi group, I am relatively new to C# (although I have a lot of programming excperience in other languages like Java and C). Currently I am searching for a solution to this problem: Suppose you...
29
by: AlFire | last post by:
Hi, I have a piece of software which uses threads in very massive way - like hundreds of them generated every second. there is also a piece of code which maintains the number of outstanding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.