LarryDietz Posted January 26, 2004 Posted January 26, 2004 I am working on a program that loads images into a picturebox, using the following line of code... picScreenShot.Image = Image.FromFile(Application.StartupPath + "\screenshots\" + GameList(SelectedGame).InternalName + ".png") This loads the image just fine. However, when I load a 2nd image (or 3rd, etc...) it continues to hold the previous files open. If I load 5 images (1 at a time) then go to windows explorer and try to delete one of the first images (which is no longer being displayed) the system will not let me. It give the following error... An unhandled exception of type 'System.IO.IOException' occurred in microsoft.visualbasic.dll Additional information: The process cannot access the file "...\screenshots\testfile.png" because it is being used by another process. It appears to be locking ALL the images it has ever opened, until I shutdown the program. This is a problem because I need the program to be able to delete some of these files. Does anyone have any idea why this error is occuring? Any help would be greatly appreciated. -Larry Quote
*Experts* mutant Posted January 26, 2004 *Experts* Posted January 26, 2004 Dispose of the PictureBox's image before putting another one in it. PictureBox1.Image.Dispose() Quote
NK2000 Posted January 26, 2004 Posted January 26, 2004 You should generally do a cleanup when you work with files, it helps to reduce bugs so always check if a StreamWriter is still open ( Writer != null ), normally you put that in the "finally" part of your try and catch Quote
LarryDietz Posted January 27, 2004 Author Posted January 27, 2004 Thank you! I will give this a try and see if it works. I really appreciate the response. I'll let you know if it worked ok. Thanks, Larry Quote
LarryDietz Posted January 27, 2004 Author Posted January 27, 2004 Well, It was a good idea, but it didnt work :( I disposed of the image, and loaded the new image. That worked just fine, and the new image displayed. Tehn when I tried to KILL the original image file from the hard drive, it errored, saying the file was in use. :( Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.