Hi there,
Say I have an ArrayList named list. What's the difference between using
lock(list) { .... }
and
lock(list.SyncRoot) { .... } 5 20357
In 1.1, IIRC, there would be no difference as list.SyncRoot was "this".
However, in 2.0, SyncRoot is not "this" but a seperate object. Use SyncRoot
if you want to lock on that. However, I would just use my own syncRoot
object in your containing class.
--
William Stacey [MVP]
"Jacob" <no****@nospamforme.comwrote in message
news:Ot**************@TK2MSFTNGP04.phx.gbl...
| Hi there,
|
| Say I have an ArrayList named list. What's the difference between using
|
| lock(list) { .... }
|
| and
|
| lock(list.SyncRoot) { .... }
|
|
|
|
"Jacob" <no****@nospamforme.comwrote:
Say I have an ArrayList named list. What's the difference between using
lock(list) { .... }
and
lock(list.SyncRoot) { .... }
You may have used ArrayList.ReadOnly or ArrayList.Synchronized to wrap
the list. SyncRoot filters through the wrappers to get the underlying
object.
Generally, ArrayList itself isn't recommended any more, and List<T>
doesn't have a SyncRoot property because it doesn't have virtual methods
- it's not designed for wrapping in the same way as ArrayList, for
performance reasons.
-- Barry
-- http://barrkel.blogspot.com/
"William Stacey [MVP]" <wi************@gmail.comwrote in message
news:ON**************@TK2MSFTNGP05.phx.gbl...
In 1.1, IIRC, there would be no difference as list.SyncRoot was "this".
However, in 2.0, SyncRoot is not "this" but a seperate object. Use
SyncRoot
if you want to lock on that. However, I would just use my own syncRoot
object in your containing class.
So it doesn't matter which way I do it as long as I always do it the same
way. Is that right?
"Jacob" <no****@nospamforme.comwrote:
So it doesn't matter which way I do it as long as I always do it the same
way. Is that right?
Like I said, it depends on whether you've got the list wrapped up by
ArrayList.Synchronized or ArrayList.ReadOnly. That's why SyncRoot was
invented.
-- Barry
-- http://barrkel.blogspot.com/
Yes. You can use any object, as long as you use the same one and you know
it does not change behind the covers somehow. For clarity, I would use my
own syncRoot in the class such as this simple example:
public class Class1
{
private readonly object syncRoot = new object();
private readonly List<intlist = new List<int>();
public object SyncRoot
{
get{return this.syncRoot;}
}
public void Add(int i)
{
lock(syncRoot)
{
list.Add(i);
}
}
//...
}
--
William Stacey [MVP]
"Jacob" <no****@nospamforme.comwrote in message
news:e9**************@TK2MSFTNGP04.phx.gbl...
|
| "William Stacey [MVP]" <wi************@gmail.comwrote in message
| news:ON**************@TK2MSFTNGP05.phx.gbl...
| In 1.1, IIRC, there would be no difference as list.SyncRoot was "this".
| However, in 2.0, SyncRoot is not "this" but a seperate object. Use
| SyncRoot
| if you want to lock on that. However, I would just use my own syncRoot
| object in your containing class.
| >
|
| So it doesn't matter which way I do it as long as I always do it the same
| way. Is that right?
|
| This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Not Me |
last post by:
Hi,
I'm sure this is a common problem.. to create a single field from a
whole column, where each row would be separated by a comma.
I can do this for a specified table, and column.. and I've...
|
by: Bruce Pullen |
last post by:
DB2 v7.2 (FP7 - DB2 v7.1.0.68) on AIX 5.2.0.0.
We're seeing unexpected single row (then commit) insert locking
behaviour.
We're seeing Applications that already hold row-level W locks in...
|
by: Tom Dauria |
last post by:
I have a form that allows the user to select some number of People
from a list. The user can select one or all of the people in the
list. The list has thousands of names.
Once the user makes...
|
by: Sharon |
last post by:
Hi all.
I have an ArrayList and
sometimes while enumerating through, i get an
exception because another thread has added to the ArrayList.
To solve this problem, i lock the enumeration,
passing...
|
by: Stu Lock |
last post by:
Hi,
Is there any way to databind a hashtable to a drop down list box using the
key/value pair within the hashtable to correspond to the value/text of the
drop down list box?
ie: hashtable...
|
by: situ |
last post by:
Hi,
we i get a snapshot for lock on db i'm getting
LOCK_LIST_IN_USE =5560
and
my LOCKLIST parameter = 50,
is it ok for OLTP database or do i have to do any tuning here.
thanks
sridhar
|
by: Geoffrey |
last post by:
Hello,
I work with .net remoting,to simplify, when the client connected, he send an
handle to an object, the object is used to exchange message and events. no
problem.
In my server, I keep a...
|
by: castironpi |
last post by:
Any ideas for a thread-safe list.removeall( X ): removing all
occurrences of X within list L, when L might be modified concurrently?
Sincerely,
Aaron
|
by: Marco |
last post by:
Hi all,
with db2 snapshot I know the lock waits number but I can not see the
tables with locks an I can not see queries that produces locks.
How can I know those details?
Thanks
Marco...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |