Dispose
Andrew Dunn <[email protected]> Thu, 12 Jul 2007 11:56:59 +1000
| Newsgroups | gmane.comp.windows.devel.dotnet.web |
|---|---|
| Message-ID | <5B2CE496DCCE2040B271D9417E72CB2815C3F2@bdbdc2.corporate.hcn.com.au> |
Hi,
Can anyone see a better way of doing this. I have a class that holds an
image as one of it's properties. This image is held in the windows temp
directory. I want to delete it when the class is destroyed. Is Dispose
the best place to do this? Is ~PatientPhoto() OK to call dispose?
public Bitmap Photo
{
get{ return _Photo;}
set{ _Photo = value;}
}
~PatientPhoto()
{
Dispose();
}
public void Dispose()
{
if(Photo != null)
{
if (Photo.Tag != null)
{
string FileLoc = Photo.Tag.ToString();
///Delete the photo file as it is stored in a
temporary file in the windows temp directory
if (File.Exists(FileLoc))
{
Photo.Dispose();
Photo = null;
try
{
File.Delete(FileLoc);
}
catch (IOException e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
}
}
}
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com