Hello All
I have an abstract class C1 with this:
public abstract class C1
{
protected bool m_Dirty;
protected override void Dispose(bool disposing)
{
if(m_Dirty)
WriteOuput();
base.Dispose (disposing);
}
protected void finalize()
{
Dispose(false);
GC.SuppressFina lize(this);
}
public abstract void WriteOuput();
}
Then I have a derived class C2 with this:
public class C2: C1
{
public override void WriteOuput()
{
if(m_Dirty)
{
try
{
m_Log.WriteXml( m_InitialData);
}
catch
{
//Ignore error if file is not valid
}
m_Dirty = false;
}
}
}
I use C2 in my code, but I don't see the parent dispose being called
since the output is never written...Am'I missing something here..??
thanks
Sunit su********@netz ero.net 4 6729
Your finalize method should be called "~C1", not "finalize".
"Sunit Joshi" <sj****@ingr.co m> wrote in message
news:8f******** *************** *@posting.googl e.com... Hello All I have an abstract class C1 with this:
public abstract class C1 { protected bool m_Dirty; protected override void Dispose(bool disposing) { if(m_Dirty) WriteOuput(); base.Dispose (disposing); }
protected void finalize() { Dispose(false); GC.SuppressFina lize(this); }
As previously noted, you should use C++ destructor syntax for your finalize
method in C#:
protected ~C1() // note: I don't think that it matters that it's protected
vs. public.
Also, I think that your call to GC.SuppressFina lize() may be in the wrong
place. You don't want it in the finalize method -- if the finalizer is
running, it means that the GC has already called suppress finalize anyway.
Instead, put the call to suppress finalize in the public version of the
Dispose method, so that if the calling code calls dispose manually, the C1
class will not have its destructor called (no need).
For a more detailed discussion, read this: http://msdn.microsoft.com/library/de...poseMethod.asp
"Sunit Joshi" <sj****@ingr.co m> wrote in message
news:8f******** *************** *@posting.googl e.com... Hello All I have an abstract class C1 with this:
public abstract class C1 { protected bool m_Dirty; protected override void Dispose(bool disposing) { if(m_Dirty) WriteOuput(); base.Dispose (disposing); }
protected void finalize() { Dispose(false); GC.SuppressFina lize(this); } public abstract void WriteOuput(); }
Then I have a derived class C2 with this:
public class C2: C1 { public override void WriteOuput() { if(m_Dirty) { try { m_Log.WriteXml( m_InitialData); } catch { //Ignore error if file is not valid } m_Dirty = false; } } }
I use C2 in my code, but I don't see the parent dispose being called since the output is never written...Am'I missing something here..??
thanks Sunit su********@netz ero.net
Hi,
In addition to the other comments in this thread your
abstract class must descend from the IDisposable
interface. The "Dispose Pattern" is documented in MSDN.
In the Dispose pattern your abstract {or base} class
should take a form like the code below. Descenders of
your abstract class can override the protected virtual
form of the Dispose method to add custom cleanup code.
class MyClass: IDisposable
{
public MyClass()
{
}
~MyClass()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFina lize(this);
}
protected virtual void Dispose(bool disposing)
{
<<implement cleanup logic here>>
}
}
--Richard -----Original Message----- Hello All I have an abstract class C1 with this:
public abstract class C1 { protected bool m_Dirty; protected override void Dispose(bool disposing) { if(m_Dirty) WriteOuput(); base.Dispose (disposing); }
protected void finalize() { Dispose(false); GC.SuppressFina lize(this); } public abstract void WriteOuput(); }
Then I have a derived class C2 with this:
public class C2: C1 { public override void WriteOuput() { if(m_Dirty) { try { m_Log.WriteXml( m_InitialData); } catch { //Ignore error if file is not valid } m_Dirty = false; } } }
I use C2 in my code, but I don't see the parent dispose
being calledsince the output is never written...Am'I missing
something here..?? thanks Sunit su********@net zero.net .
Typo, sorry: it means that the GC has already called suppress finalize anyway.
I meant to say that the GC has already called finalize anyway.
"J.Marsch" <je****@ctcdeve loper.com> wrote in message
news:e4******** ******@TK2MSFTN GP12.phx.gbl... As previously noted, you should use C++ destructor syntax for your
finalize method in C#: protected ~C1() // note: I don't think that it matters that it's
protected vs. public.
Also, I think that your call to GC.SuppressFina lize() may be in the wrong place. You don't want it in the finalize method -- if the finalizer is running, it means that the GC has already called suppress finalize anyway.
Instead, put the call to suppress finalize in the public version of the Dispose method, so that if the calling code calls dispose manually, the C1 class will not have its destructor called (no need).
For a more detailed discussion, read this: http://msdn.microsoft.com/library/de...poseMethod.asp
"Sunit Joshi" <sj****@ingr.co m> wrote in message news:8f******** *************** *@posting.googl e.com... Hello All I have an abstract class C1 with this:
public abstract class C1 { protected bool m_Dirty; protected override void Dispose(bool disposing) { if(m_Dirty) WriteOuput(); base.Dispose (disposing); }
protected void finalize() { Dispose(false); GC.SuppressFina lize(this); } public abstract void WriteOuput(); }
Then I have a derived class C2 with this:
public class C2: C1 { public override void WriteOuput() { if(m_Dirty) { try { m_Log.WriteXml( m_InitialData); } catch { //Ignore error if file is not valid } m_Dirty = false; } } }
I use C2 in my code, but I don't see the parent dispose being called since the output is never written...Am'I missing something here..??
thanks Sunit su********@netz ero.net
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robert |
last post by:
Hello all...
In my code below, the Notify Constructor and Destructor is getting
called twice and it appears that a new Notify object is created on the
2nd call. The 2nd call is caused by this line below: pNotify = new
EMAILnotify; that lives in the Notification Constructor.
One theory is that the Notify base class is not completely constructed
prior to using it in the Notification Constructor code: pNotify = new
EMAILnotify;
|
by: Adam Clauss |
last post by:
I have a webapp which consists of several different webforms.
Basically:
(1) view the contents of a database
(2) one is to add a new entry
(3) confirms the new entry.
The third form, upon confirming the entry (in a button_clicked handler) adds
the entry into the database and then redirects back to (2) using
Response.Redirect(..)
|
by: samir dsf |
last post by:
hi
I had been using this datagrid for long. all well...but suddenly the
itemdatabound event is not at all getting called...i dont see my
links..initally it worked well
here is the page_load and itemdatabound event.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
|
by: Erik |
last post by:
Why isn't my update method getting called?
Pasted below is an aspx from a 1.1 application I'm working on. It has
two textboxes and a button for inserting data into the database, and a
datagrid for editing and deleting data. When a user clicks on the
"Edit" button in the datagrid, Edit() method is called and the
appropriate row is changed into textboxes. And if user clicks on the
"Update" button, the Update() method is fired. But if...
|
by: jm.suresh |
last post by:
In the following code, I could not find out why the set and get methods
are not called once I set the property.
.... def __init__(self):
.... self._color = 12
.... def _setcolor(self,value):
.... print 'setting'
.... self._color = value
.... def _getcolor(self):
| |
by: sean |
last post by:
I'm trying to create "rubber-band" rectangles by overriding the
OnPaint method to place rectangles on top of all graphic controls, but
when I call Me.Invalidate() (when the user moves the mouse), OnPaint
is not getting called... Here is the relevent code:
I'm trying to create a "rubber band" rectangle effect on my form.
Private Sub HighlightSectionOfTrack(ByVal sender As Object, ByVal e
As
System.Windows.Forms.MouseEventArgs) Handles...
|
by: Abubakar |
last post by:
Hi,
I have a dll that gets called by an exe, I just placed a little code in its
dlmain method and put a breakpoint on the code only to discover that its
getting called nearly hundreds of times. I suspect each time some exported
function is getting called the dllmain also gets called. Why is it happening
and why should it happen?
Regards,
...ab
|
by: SAL |
last post by:
Hello,
I'm working, basically my first, AJAX page and am having a few problems.
One is that the Click event for a button I have in UpdatePanel1 is not
getting called. I've tried with the button both inside and outside of the
updatepanel and the event doesn't get called either way. What might I be
missing here?
Incidently, something else, kind of weird, is happening when the button is
clicked, a required field validator control in a...
|
by: hgarg |
last post by:
The onpaint() is getting called before calculating the required parameters by listBox1_SelectedIndexChanged function. I tried calling it at the end of this function. But of no use. Due to this issue only half of the diagram is getting painted,some lines are missing in the diagram.
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string str=listBox1.SelectedItem.ToString();
string str1=null;...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |