Solved

Delete on Exit in C#

Posted on 2006-07-11
5
1,402 Views
Last Modified: 2012-05-05
Hi,

I would like to know the equivalent of java.io.deleteonExit equivalent function in c#

because it is related to JVM what is the equivalent in c#
0
Comment
Question by:Rahamathulla_J
  • 2
  • 2
5 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 17080806
Hi Rahamathulla_J,
----------

there is none, according to msdn you need to put your file into a variable which is deleted explicitly on application termination
http://msdn2.microsoft.com/en-us/library/tbkw12c2.aspx

----------
bruintje
share what you know, learn what you don't
0
 

Author Comment

by:Rahamathulla_J
ID: 17081686
i don't know how to put the file in a variable and where to put that code in the project because i am not sure where the application is terminate in Java code.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17082923
from what i rad about the deleteonexit its only called upon when the java runtime is closing down [through user intervention or unexpected] not the application just to clean up open handles

but i could be wrong here

is this java application always on? i mean is it never terminated through user interaction?
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 17085643
I believe you mean "java.io.File.deleteonExit" not java.io.deleteonExit...

There is no analogue in C#.
I think what you need to do is just call File (C#) static method "Delete" when you exit your application. You don't need any variables.
You just pass a file path as a parameter:

            // Delete the previously created file.
            File.Delete(filepath);
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 250 total points
ID: 17087971
One more idea.

If in Java you use some files and want to delete them "on exit" - these are temporary files.
OK, you have them in .Net. When your job is done you may delete these files or just let windows do it the next time the machine is rebooted

Read: http://www.knowdotnet.com/articles/tempfiles.html


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now