I have a class that makes use of temporary files (Path.GetTempFileName()
) while it is active. I want to make sure these files do not remain on the user\'s hard driv
You should definitely use Dispose
to clean up resources, but make sure you implement the IDisposable
interface. You don't want to just add a method named Dispose
.
A file is an unmanaged resource, and you implement IDisposable to clean up unmanaged resources that your classes are dependent upon.
I have implemented similar classes, although never in production code.
However, I understand your tentativeness about this - user interaction with the files outside of your application could screw things up and cause problems during disposal. However, that is the same for any file created/deleted by an application, regardless of whether or not it's tidied up by a Dispose() method or not.
I'd have to say that implementing IDisposable would be a reasonable choice.