By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

Hashtable.Synchronzied()

P: n/a
Hi,

Using the following code

Hashtable myData = Hashtable.Synchronized(new Hashtable());

Then I will be having a main thread that will write to this hashtable,
and other n threads that will read and write to this hashtable. In the
n threads, when reading and writing, only one thread will be assigned
specifically on place in the hashtable.

Thread 1 will access only data in myData[1]
Thread 2 will access only data in myData[2]
Thread 3 will access only data in myData[3]
....

Having this scenario, is there need to use the lock(this){...}
mechanism on the Hashtable.
Can someone help me out
Thanks in Advance

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ron
You don't need to use lock(this){...}, you are already synchronizing the
hashtable.

"be*********@yahoo.com" wrote:
Hi,

Using the following code

Hashtable myData = Hashtable.Synchronized(new Hashtable());

Then I will be having a main thread that will write to this hashtable,
and other n threads that will read and write to this hashtable. In the
n threads, when reading and writing, only one thread will be assigned
specifically on place in the hashtable.

Thread 1 will access only data in myData[1]
Thread 2 will access only data in myData[2]
Thread 3 will access only data in myData[3]
....

Having this scenario, is there need to use the lock(this){...}
mechanism on the Hashtable.
Can someone help me out
Thanks in Advance

Nov 17 '05 #2

P: n/a
Ron <Ro*@discussions.microsoft.com> wrote:
You don't need to use lock(this){...}, you are already synchronizing the
hashtable.


Unless, of course, you want to have a whole sequence of operations
synchronized, rather than just one at a time.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3

P: n/a
If there is an other Thread thread0, that will have the right to access
all information in Hashtable, will there be the need to use the lock?

Where should it be used in this thread0 or in the other threads, or in
all?

Thanks for your help

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.