473,378 Members | 1,106 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,378 software developers and data experts.

where to call savetoxml to run on object destruction

I'm using an object that has a dataset within it.
When the object is instantiated I populate the dataset from xml files.
I want the object to save the dataset back to the xml file before it is
destroyed, but I'm not sure when to call this routine. Should I call it
from the object's destructor or should it implement the IDisposable
interface?

Thanks!
May 10 '07 #1
3 1303
deciacco,

You should implement the IDisposable interface. In the Dispose method,
you should write the file.

The suggested pattern for implementing IDispose has the finalizer run
the same code (with a variation). For this kind of activity, I would say to
not do this, as it appears that you are looking for specific lifetime
management. Since finalization is non-deterministic, calling the code from
there would be a bad idea.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"deciacco" <a@awrote in message
news:Mv******************************@giganews.com ...
I'm using an object that has a dataset within it.
When the object is instantiated I populate the dataset from xml files.
I want the object to save the dataset back to the xml file before it is
destroyed, but I'm not sure when to call this routine. Should I call it
from the object's destructor or should it implement the IDisposable
interface?

Thanks!

May 10 '07 #2
Thanks for the reply,

Forgive me, but I'm pretty new to C# and I do not understand the second
part.

Are you saying that if I do it, I should use IDisposable, but this isn't
a good way either?

Nicholas Paldino [.NET/C# MVP] wrote:
deciacco,

You should implement the IDisposable interface. In the Dispose method,
you should write the file.

The suggested pattern for implementing IDispose has the finalizer run
the same code (with a variation). For this kind of activity, I would say to
not do this, as it appears that you are looking for specific lifetime
management. Since finalization is non-deterministic, calling the code from
there would be a bad idea.

May 10 '07 #3
No, I am saying you should implement IDisposable, but don't place the
logic in the finalizer to write the file.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"deciacco" <a@awrote in message
news:38******************************@giganews.com ...
Thanks for the reply,

Forgive me, but I'm pretty new to C# and I do not understand the second
part.

Are you saying that if I do it, I should use IDisposable, but this isn't a
good way either?

Nicholas Paldino [.NET/C# MVP] wrote:
>deciacco,

You should implement the IDisposable interface. In the Dispose
method, you should write the file.

The suggested pattern for implementing IDispose has the finalizer run
the same code (with a variation). For this kind of activity, I would say
to not do this, as it appears that you are looking for specific lifetime
management. Since finalization is non-deterministic, calling the code
from there would be a bad idea.
May 10 '07 #4

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

Similar topics

17
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
9
by: Daniel Kay | last post by:
Hello! I have written two template classes which implement the observerpattern in C++. I hope I manage to desribe the problem I have. template<class T> class Observer { /* ... */ }; ...
11
by: fourfires.d | last post by:
Dear All, I am new to c++ and when write below code that try to call copy constructor in "=" operator overloading, it can not compile. Can anyone point out for me the reason? thanks !! ...
15
by: cedgington | last post by:
I wanted to take advantage of the large set of functionality offered by the framework, so for my latest project I'm using managed C++ with .NET v2. I'm using the gcnew operator in two different...
6
by: Pablo | last post by:
Hello, I am writing a windows application using C++ and BorlandBuilder 6 compiler. It is an event driven program and I need to create objects of some classes written by me. One of the classes...
7
by: michael | last post by:
Hi All, I have written the following to illustrate a problem. I know I have some magic numbers etc please ignore them. What I do not follow is why the line marked results in a call to the...
1
by: appu | last post by:
Hi all, Suppose class A is inherited from class B and Class B is inherited from class C. Could anyone explain on how the C++ compiler construct the A object and how is A object destroyed by...
2
by: dolphin | last post by:
What is the different between c++ call convention and c call convention?Can some give some examples?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.