Re: Is Singleton collection of Singletons possible??

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 03/08/04


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


Relevant Pages

  • Re: Is Singleton collection of Singletons possible??
    ... > with an ArgumentException. ... each call locking all other calls out until it completed. ... you're dealing with shared data, take out a lock. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is Singleton collection of Singletons possible??
    ... you wouldn't end up with an ArgumentException - you'd end up with ... which is why I will evaluate whether just adding the locking would ... be simpler than dealing with the exceptions. ... To guarantee thread safety during enumeration, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Image.SetPropertyItem does not work
    ... However when I restart the PC, the exception gone... ... Assuming that there's nothing important in the code you left out, we're either back to some issue with the PropertyItem itself, or an OS/.NET version difference. ... You should be able to use that without any additional effort to see whether you see a locking issue on your configuration; if not, then there's something about the specific usage your code has that's causing problems, rather than a general failure with a locked file. ... I have no Windows 7 to test, but if what you said is true then I think it is version-specific issue. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Open files and locks
    ... Thank you for the response. ... if a file has a lock and throws an ... exception that tells me its locked but not who is locking it. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: LazyLoad
    ... there is a problem with my locking. ... Both Lazy objects don't share the same Mutex object, so, ... raise @exception if @exception ... def lazy ...
    (comp.lang.ruby)