property access after Dispose()

From: dirk diggler (shoveyerspamupyer@ss.com)
Date: 09/20/02


From: "dirk diggler" <shoveyerspamupyer@ss.com>
Date: Fri, 20 Sep 2002 01:38:09 -0700


just an opinion, but i think that it should be A - throw
exceptions on all attempts to access once disposed. This
is because, when you dispose of an object you are
explicitly saying i have finished with it (after all it
isn't absolutely necessary to dispose) and i want the
resources i have used to be freed up so they can be re-
used.

Just a guesss, but the properties that are not throwing
exceptions, could it be that Garbage Collection hasn't yet
happened for those yet?

>-----Original Message-----
>Hi,
>
>Microsoft's .NET documentation suggests that the object
>become "unusable" after a Dispose() is invoked on it.
>I've seen classes in the .NET class library throw
>exceptions when a method is called on a disposed method,
>which seems to be consistent all around. However, I've
>seen a mixed bag when it comes to properties of a
disposed
>object. Some properties throw exceptions and some do not
>when they're accessed after the dispose is called. I'm
>currently designing my own class library and I'm not sure
>exactly what approach I should take when properties are
>accessed on a disposed object. Should the disposed
>object ...
>
>a) always throw exceptions when properties are accessed
on
>a disposed object?
>b) return whatever property values that were present
>before the dispose was called?
>c) return the default values of the property
>d) only throw an exception if the property value cannot
be
>returned due to the resources freed by Dispose()?
>
>Any help is appreciated! Thanks!!
>
>- norm.
>.
>



Relevant Pages

  • Re: Paradigm for multiple IDisposables
    ... you and call IDisposable in the face of exceptions. ... IDisposable on MultiDispose, you have to wrap the call to Dispose on each ... a list of IDisposables inside the using statement, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Retrieve thrown exception in using (disposable) cleanup
    ... Thanks for the suggestion. ... I hoped it might be possible to detect thrown exceptions in the same way ... Can you save ErrorException in a field until Dispose ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: property access after Dispose()
    ... > Microsoft's .NET documentation suggests that the object ... > become "unusable" after a Dispose() is invoked on it. ... > I've seen classes in the .NET class library throw ... Some properties throw exceptions and some do not ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • property access after Dispose()
    ... become "unusable" after a Dispose() is invoked on it. ... I've seen classes in the .NET class library throw ... exceptions when a method is called on a disposed method, ... Some properties throw exceptions and some do not ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Is this pattern OK?
    ... They also cope with the possibility of Dispose calls throwing ... exceptions - with a single finally block, ... World class .NET training in the UK:http://iterativetraining.co.uk ...
    (microsoft.public.dotnet.languages.csharp)