J
Jon Q Jacobs
Guest
I display some Bitmap objects in some PictureBox controls. In the course of processing I am done with certain of the .bmp files and want to delete them. I also cannot rename them, move them, or anything.
I keep the (PictureBox objects in a list, and the Bitmap files to delete in a list.
foreach (PictureBox pbx in pbxs)
{
try
{
Bitmap bmp = (Bitmap)pbx.Image;
pbx.Image = null;
pbxs.Remove(pbx);
pbx.Dispose();
bmp.Dispose();
bmp = null;
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
for (int i = ToDelete.Count - 1; i >= 0; i--)
{
string FQFN = ToDelete;
try
{
File.Delete(FQFN);
ToDelete.Remove(FQFN);
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
In spite of disposing of the Bitmap objects and the PictureBox objects, trying to delete the .bmp files gives me a "in use by another process" exception.
When I exit the program, I have no trouble deleting the files from Windows Explorer. I do not create any background threads, etc. in the application.
What is going on?
Jon Jacobs
Jon Jacobs, There are 10 kinds of people: those who understand binary and those who don't
Continue reading...
I keep the (PictureBox objects in a list, and the Bitmap files to delete in a list.
foreach (PictureBox pbx in pbxs)
{
try
{
Bitmap bmp = (Bitmap)pbx.Image;
pbx.Image = null;
pbxs.Remove(pbx);
pbx.Dispose();
bmp.Dispose();
bmp = null;
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
for (int i = ToDelete.Count - 1; i >= 0; i--)
{
string FQFN = ToDelete;
try
{
File.Delete(FQFN);
ToDelete.Remove(FQFN);
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
In spite of disposing of the Bitmap objects and the PictureBox objects, trying to delete the .bmp files gives me a "in use by another process" exception.
When I exit the program, I have no trouble deleting the files from Windows Explorer. I do not create any background threads, etc. in the application.
What is going on?
Jon Jacobs
Jon Jacobs, There are 10 kinds of people: those who understand binary and those who don't
Continue reading...