PC Review


Reply
Thread Tools Rate Thread

Destructor for VB.NET class

 
 
Mika M
Guest
Posts: n/a
 
      4th Apr 2005
Hi!

My application uses self made Class. When I create an instance of it,
class creates temporary file in constructor, and this file is in use as
long as instance of class is in use.

After instance of class will be removed, temporary needed file should be
deleted too. So how can I do it? It there destructor for VB.NET class
where this file can be deleted or something like that? I'm quite newbie
with VB.NET OOP programming, but I have studied UML. Maybe I have missed
something

I mean something like...

Dim cl As MyClass = New MyClass
'// Here temporary file is created
cl.DoSomething()
'// Here temporary file is in use
cl = Nothing
'// After previous line temporary file should be deleted to avoid next
line, but how ?

If (File.Exists(strTempFilePath)) Then File.Delete(strTempFilePath)

--
Thanks in advance!

Mika
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Apr 2005
"Mika M" <mahmik_nospam@removethis_luukku.com> schrieb:
> My application uses self made Class. When I create an instance of it,
> class creates temporary file in constructor, and this file is in use as
> long as instance of class is in use.
>
> After instance of class will be removed, temporary needed file should be
> deleted too. So how can I do it? It there destructor for VB.NET class
> where this file can be deleted or something like that?


Take a look at the chapters about the GC, finalization and the 'IDisposable'
('Dispose' method) interface. Feel free to ask if this doesn't answer your
questions...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

 
Reply With Quote
 
Crouchie1998
Guest
Posts: n/a
 
      4th Apr 2005
If you use the If File.Exists method you may come across a file access
error. My advice would be to sleep the application a split second whilst you
close the file, destroy the stream writer or whatever you are using... &
then use the File.Exists method

Another way would be to do the above in dispose. Calling the garbage
collector will clean up the object reference, but not the temporary file

I hope this was of some help

Crouchie1998
BA (HONS) MCP MCSE


 
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
A class destructor Trecius Microsoft C# .NET 4 20th Oct 2008 04:40 PM
Closing database connections in a class destructor Mark Rae Microsoft C# .NET 15 28th Apr 2005 09:53 AM
C++ vc C#. Destructor of not created class get called. Daniel O'Connell [C# MVP] Microsoft Dot NET Framework 5 5th Jun 2004 04:57 PM
C++ vc C#. Destructor of not created class get called. Daniel O'Connell [C# MVP] Microsoft C# .NET 5 5th Jun 2004 04:57 PM
ICE on VC7.1 when destructor is defined but not delcared in class Jonathan Turkanis Microsoft VC .NET 3 5th Apr 2004 08:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:35 AM.