Problem to remove temporary image files once used
-
hi friends, seniors $ all, I have a form on which i am using layout panel. on this layout panel i am adding user control during runtime. the control consists of a picturebox and label. the image which is displayed on picture box is copied from the source folder to temp folder. this image is resized and bitmap is created and passed to picture box. now i want to clear the temporary moved files, which is not happening.. :( i get the file is in use. so i disposed the child form, before comming to parent form. even clearing the layout panel didint help.. friends please suggest me some help regards Samir
-
hi friends, seniors $ all, I have a form on which i am using layout panel. on this layout panel i am adding user control during runtime. the control consists of a picturebox and label. the image which is displayed on picture box is copied from the source folder to temp folder. this image is resized and bitmap is created and passed to picture box. now i want to clear the temporary moved files, which is not happening.. :( i get the file is in use. so i disposed the child form, before comming to parent form. even clearing the layout panel didint help.. friends please suggest me some help regards Samir
Which of the many available Methods are you using to load the bitmap? I suspect that you are using
Image.FromFile()
as this is a well documented problem with this method. If that is correct then switch toImage.FromStream()
(look it up). Hopefully this will resolve your problems.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
Which of the many available Methods are you using to load the bitmap? I suspect that you are using
Image.FromFile()
as this is a well documented problem with this method. If that is correct then switch toImage.FromStream()
(look it up). Hopefully this will resolve your problems.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
hi sir, i am using filestream only.. one more thing i am using thread to load the controls inside layout panel regards samir
In that case, without seeing any code, is there a possibility that the threads are terminating before properly closing the streams?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
hi friends, seniors $ all, I have a form on which i am using layout panel. on this layout panel i am adding user control during runtime. the control consists of a picturebox and label. the image which is displayed on picture box is copied from the source folder to temp folder. this image is resized and bitmap is created and passed to picture box. now i want to clear the temporary moved files, which is not happening.. :( i get the file is in use. so i disposed the child form, before comming to parent form. even clearing the layout panel didint help.. friends please suggest me some help regards Samir
In order to be able to delete a file, everything that points to the file must have been disposed. Candidates are:
Image.FromFile
,Image.FromStream
,PictureBox.ImageLocation
The problem here is you have to do special things at the end of the PictureBox's life; if the image is used in more than one location in your code, it may be hard to correctly decide on its disposal. There also is a different approach, where the problem is avoided beforehand, by copying the image; this is a schematic example:Image image1=Image.FromFile(...); Bitmap bitmap1=new Bitmap(image1); // bitmap1 is unrelated to the file! image1.Dispose(); // now the file is deletable PictureBox.Image=bitmap1; ... myForm.Close(); // will lead to PictureBox disposal // bitmap1 will be garbage collected at some point, this does not affect the file
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.