Locking the syncroot will only help if all code locks it or you create a
synchonrized collection which will use the syncroot internally in add /
remove operations

I blogged about this recenly at [1]

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

[1]
http://staff.develop.com/richardb/weblog/PermaLink.aspx/870417fa-dc59-4c8d-9
dad-a68b98b24457

> -----Original Message-----
> From: Unmoderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Sriram Krishnan
> Sent: 12 October 2004 16:07
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] Multithreading question
>
> I don't think this will help you. myList.SyncRoot does the
> locking for you when you go through it - but I don't think
> locking on it is going to achieve anything.
>
> To keep something safe, you have to make sure *all your code*
> that accesses that list does one of 2 things
>
> 1. Calls lock on that list
>
> 2. Goes through the SyncRoot
>
> There is no way you can protect against someone accessing the
> list from some other thread - all the lock keyword does is
> call Monitor.Enter and Exit for you. Those methods take care
> of putting the right SyncBlockIndex into the object's header
> (at a negative offset in memory,actually)
>
>
> Sriram
>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.775 / Virus Database: 522 - Release Date: 08/10/2004

===================================
This list is hosted by DevelopMentor®  http://www.develop.com
Some .NET courses you may be interested in:

Essential .NET: building applications and components with CSharp
August 30 - September 3, in Los Angeles
http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to