473,395 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dispose Event


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
Nov 16 '05 #1
2 9593
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/<u$**************@tk2msftngp13.phx.gbl>
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;
Nov 16 '05 #2

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.

"Richard Blewett [DevelopMentor]" <ri******@develop.com> wrote in message
news:u9**************@TK2MSFTNGP11.phx.gbl...
: 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/<u$**************@tk2msftngp13.phx.gbl>
:
:
: 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;
:
:
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
3
by: Giovanni Bassi | last post by:
Hello Group, I am running an operation in a different thread. There are resources that are released when the thread is done running. This is done at the end of the execution as it raises an...
19
by: Nathan | last post by:
I know this has been asked previously, but I've run into a situation where I need to know the difference between close and dispose, and I can't get the information I need from msdn help or previous...
9
by: Charles Law | last post by:
I have a form on which user controls are placed at runtime. When a control is added to the form a handler is added for an event that a high-level object raises, which must be handled by the new...
156
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created...
9
by: Geoff Callaghan | last post by:
I have several functions that require doing a New on a local object. If the object is local to a sub or function, do I need to dispose of it, or will it just go away like any other local variable?...
3
by: TheSteph | last post by:
Hi, In the example below, do I have to call Dispose for the 2 ImageList ? Do I have to do it in the Form.Disposed event ? public class FRM_NavBrowseConfig : Form { //... private ImageList...
11
by: BLUE | last post by:
I've a class A that implements IDisposable interface and has a method that start a thread. In Dispose(bool) can I use the lock keyword to wait for thread exit before disposing resources it use or...
0
by: BillCo | last post by:
I'm a C# Newbie, so if I've missed the obvious here go easy!!! I have a form opened from a MDI parent. The form has a data bound combo box, with a SelectedIndexChanged event (fills a list view...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.