Re: Is Singleton collection of Singletons possible??
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 03/08/04
- Next message: Chuck: "Re: Access is denied problem. Please help"
- Previous message: Adam: "Strange dropdown behavior"
- In reply to: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Next in thread: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Reply: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 8 Mar 2004 22:15:12 -0000
Daniel Billingsley <dbillingsley@NO.durcon.SPAAMM.com> wrote:
> > No, you wouldn't end up with an ArgumentException - you'd end up with
> > each call locking all other calls out until it completed.
>
> Well, yes maybe so, but then the 2nd thread would get an ArgumentException
> when it tried to use an existing key in the Add method, as is normally the
> case in that method, wouldn't it? How else could you justify the statements
> a) multiple writers are supported through the synchronized wrapper and b)
> the ArgumentException is raised with Add is used with an existing key?
That a writer can use methods other than Add. In particular, I usually
use the indexer, which *doesn't* throw an ArgumentException. Otherwise
yes, with Add you would get an exception the second time, if you're
using the same key. (Using the unsynchronized version, you wouldn't
even be guaranteed to keep the data consistent though - both calls may
succeed, with one of the adds being lost, whether or not they're using
the same key. I suspect it wouldn't happen, but it's not guaranteed
that it wouldn't.)
> Again, handling the exceptions would likely be more trouble than its worth
> as compared to just doing the locking myself, but it seems it would be
> possible. I'm trying to understand why you think otherwise - i.e. what I'm
> missing.
Possibly only the option of not using an indexer.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Chuck: "Re: Access is denied problem. Please help"
- Previous message: Adam: "Strange dropdown behavior"
- In reply to: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Next in thread: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Reply: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|