PC Review


Reply
Thread Tools Rate Thread

where to call savetoxml to run on object destruction

 
 
deciacco
Guest
Posts: n/a
 
      10th May 2007
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!
 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      10th May 2007
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]
- (E-Mail Removed)

"deciacco" <a@a> wrote in message
news:(E-Mail Removed)...
> 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!



 
Reply With Quote
 
deciacco
Guest
Posts: n/a
 
      10th May 2007
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.
>
>

 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      10th May 2007
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]
- (E-Mail Removed)

"deciacco" <a@a> wrote in message
news:(E-Mail Removed)...
> 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.
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object destruction VB.NET 2005 Sid Price Microsoft VB .NET 18 2nd Mar 2008 09:15 AM
Object Destruction in Managed C++ code Craig Whatley Microsoft VC .NET 2 9th Jul 2004 02:33 PM
Object reference not set to an instance of an object error during netapi32 call Kurt Van Campenhout Microsoft VB .NET 1 18th Nov 2003 09:30 PM
Object destruction event Chewie2112 Microsoft VB .NET 2 14th Oct 2003 10:39 PM
Theoretical Question : Explicit Object 'Destruction' jdn Microsoft C# .NET 3 31st Jul 2003 07:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:08 PM.