• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1459
  • Last Modified:

Delete on Exit in C#

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
Rahamathulla_J
Asked:
Rahamathulla_J
  • 2
  • 2
1 Solution
 
bruintjeCommented:
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
 
Rahamathulla_JAuthor Commented:
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
 
bruintjeCommented:
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
 
anarki_jimbelCommented:
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
 
anarki_jimbelCommented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now