Dispose Event

  • Thread starter Thread starter SpotNet
  • Start date Start date
S

SpotNet

Hi NewsGroup,

Just got a hold of disposing and finalisers (destructors) on how to
effictively use them and understand what's going on with them, with great
thanks to this new group (thanks all). I would like to ask in when should
the disposed event be utilised for components\classes that offer them? Any
context for example;

Public Class Jet40Connection: IDisposable
{
private OleDbConnection jetconnection = null;
private bool isdisposed = false;

public Jet40Connection()
{
jetconnection = new OleDbConnection();
jetconnection.Disposed += new EventHandler(jetconnection_Disposed);
//Maybe I want this event...
}

public void Dispose()
{
this.Dispose(true);
GC.SupressFinalize(this);
}

private void Dispose(bool disposing)
{
if (!isdisposed)
{
if (disposing)
{
//-----and the rest of it, close the connection, release it,
etc
}
}
}

private void jetconnection_Disposed(object sender, EventArgs e)
{
// ??????????????????????
}

~Jet40Connection()
{
this.Dispose(false)
}
}

Not only specifically to this example, what code would the _Disposed run if
it were implemented?

Many thanks and regards,

SpotNet
 
In this case I don't see anything useful that can be done there, but in general think about this type of scenario:

An IDisposable class manages another IDisposable class and will hand out a reference to it in some situations on the understanding that this it is the only one that will call Dispose on the object its managing. So code that has received this contained object subscribes to the Disposed event so they will know not to use that object anymore when the event gets raised.

Regards

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

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>


Hi NewsGroup,

Just got a hold of disposing and finalisers (destructors) on how to
effictively use them and understand what's going on with them, with great
thanks to this new group (thanks all). I would like to ask in when should
the disposed event be utilised for components\classes that offer them? Any
context for example;
 
Thanks Richard certainly cleared that issue up I now know I don't need it in
my example context and do now know when I would require a dispose event.
Thanks again.

SpotNet.

: In this case I don't see anything useful that can be done there, but in
general think about this type of scenario:
:
: An IDisposable class manages another IDisposable class and will hand out a
reference to it in some situations on the understanding that this it is the
only one that will call Dispose on the object its managing. So code that has
received this contained object subscribes to the Disposed event so they will
know not to use that object anymore when the event gets raised.
:
: Regards
:
: Richard Blewett - DevelopMentor
: http://staff.develop.com/richardb/weblog
:
:
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>
:
:
: Hi NewsGroup,
:
: Just got a hold of disposing and finalisers (destructors) on how to
: effictively use them and understand what's going on with them, with great
: thanks to this new group (thanks all). I would like to ask in when should
: the disposed event be utilised for components\classes that offer them? Any
: context for example;
:
:
 
Back
Top