Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posted

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. :(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...