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

Destructor for VB.NET class

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
Nov 21 '05 #1
2 5480
"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/>

Nov 21 '05 #2
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
Nov 21 '05 #3

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

Similar topics

22
by: Marcin Vorbrodt | last post by:
Taken out of C++ In a Nutshell book... Example 7-18: Using an abstract classes as interface specification. struct Runnable { virtual void run() = 0; }; struct Hashable { virtual size_t...
11
by: Stub | last post by:
Please answer my questions below - thanks! 1. Why "Derived constructor" is called but "Derived destructor" not in Case 1 since object B is new'ed from Derived class? 2. Why "Derived destructor"...
4
by: iceColdFire | last post by:
Hi @all, I am trying to include struct and class objects in a union ,like class A{ int a; A(){} }; struct B {
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...
35
by: Peter Oliphant | last post by:
I'm programming in VS C++.NET 2005 using cli:/pure syntax. In my code I have a class derived from Form that creates an instance of one of my custom classes via gcnew and stores the pointer in a...
14
by: gurry | last post by:
Suppose there's a class A. There's another class called B which looks like this: class B { private: A a; public : B() { a.~A() } }
1
by: kasiyil | last post by:
Hello, I have a question about constructors and destructors in C++. Assume that I declared a class that has a constructor and virtual destructor like below: class X { X() { printf...
4
by: Richard | last post by:
First question - let's get this out of the way since it might be the solution to all my woes: Does it make sense to have a .cpp file for a class that is declared as having pure virtual functions...
23
by: Ben Voigt | last post by:
I have a POD type with a private destructor. There are a whole hierarchy of derived POD types, all meant to be freed using a public member function Destroy in the base class. I get warning C4624....
1
by: johnsonlau | last post by:
When a class derives from a class, You can use a pointer to the parent class to delete the instance of child only when a virtual destructor declared in the parent. class Parent { virtual...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.