J
Jeff Gaines
I have written a file manage in C Sharp / .NET Framework 2.
I want to show thumbnails for image files and use the following to get an
Image I can use as a thumbnail:
public void SetThumbnail(FileInfo fInfo)
{
string imageFilter = "*.jpg;*.png;*.gif;*.bmp;*.ico";
Image imgTemp;
// Only try for image for image files
if (imageFilter.Contains(fInfo.Extension.ToLower()))
{
try
{
// Image.FromFile locks the image until it is disposed so would prevent
moving/deleting the file
imgTemp = Image.FromFile(fInfo.FullName);
this.ThumbImage = (Image)imgTemp.Clone();
imgTemp.Dispose();
}
catch
{
}
}
else
{
try
{
imgTemp = JLibrary.ImageFromPath(fInfo.FullName);
this.ThumbImage = (Image)imgTemp.Clone();
imgTemp.Dispose();
}
catch
{
}
}
}
}
However, when I try to move/delete an image file with an extension
contained in imageFilter I get an error message that the file is open in
vshost.exe. When I don't call SetThumbnail then I can move/delete image
files at will.
The images concerned come from Image.FromFile, i.e. they are contained in
imageFilter and I had hoped by cloning the image and then disposing the
original I could overcome this issue. However, that is not the case.
The good news is I have had the problem for a year or so and have managed
to pin down where it arises - the bad news is I don't know how to overcome
the problem.
Any suggestions please, I have done what I thought I needed to do but it's
not working as I expected.
I want to show thumbnails for image files and use the following to get an
Image I can use as a thumbnail:
public void SetThumbnail(FileInfo fInfo)
{
string imageFilter = "*.jpg;*.png;*.gif;*.bmp;*.ico";
Image imgTemp;
// Only try for image for image files
if (imageFilter.Contains(fInfo.Extension.ToLower()))
{
try
{
// Image.FromFile locks the image until it is disposed so would prevent
moving/deleting the file
imgTemp = Image.FromFile(fInfo.FullName);
this.ThumbImage = (Image)imgTemp.Clone();
imgTemp.Dispose();
}
catch
{
}
}
else
{
try
{
imgTemp = JLibrary.ImageFromPath(fInfo.FullName);
this.ThumbImage = (Image)imgTemp.Clone();
imgTemp.Dispose();
}
catch
{
}
}
}
}
However, when I try to move/delete an image file with an extension
contained in imageFilter I get an error message that the file is open in
vshost.exe. When I don't call SetThumbnail then I can move/delete image
files at will.
The images concerned come from Image.FromFile, i.e. they are contained in
imageFilter and I had hoped by cloning the image and then disposing the
original I could overcome this issue. However, that is not the case.
The good news is I have had the problem for a year or so and have managed
to pin down where it arises - the bad news is I don't know how to overcome
the problem.
Any suggestions please, I have done what I thought I needed to do but it's
not working as I expected.