Is IDisposable missing something???

Note: this entry has moved.

Who about:

public interface IDisposable
{
      event EventHandler Disposed;
      void Dispose();
      bool IsDisposed { get; }
}
That would make it feasible to have features that monitor for the disposal of elements to do something (like cleanup related state, etc.). For the record, the Disposed event *is* exposed in the IComponent interface.... too bad it didn't make it to the IDisposable interface :( .... (at least I'd like the event ...)

5 Comments

  • IDisposable.Dispose is supposed to be called multiple times so IsDisposed doesn't make much sense.

  • Control.Show() is also supposed to be called multiple times, but that doesn't render Control.Visible useless, does it? :p

  • Nothing so stop you implementing this pattern in your classes. But it just adds work to implementing Dispose: e.g. what to do if the Dispose event throws an exception? Ensure the Dispose event isn't fired if disposing from the finalizer as this will probably be risky. So I don't think it's appropriate for the general case of providing the simplest possible way to dispose unmanaged resources.

  • Completly agree with you-is CLR managed environment?If so,I must be able to trace use of my resources;-)

    Little notice,I tried to find means to trace closed event in XmlReader for simple purpose:

    XmlResolver{

    object GetEntity(){

    OracleConnection conn;

    ...

    OracleReader r;

    ...

    XmlReader xr= XmlReader.Create( r.GetOracleLob(0));//stream

    xr.Disposed+=...;//what I searching for to close connection object

    return xr;

    }

    }

  • Hahaha... good joke Pablo :p ...

Comments have been disabled for this content.