"In use by another process"

bonedoc

Well-known member
Joined
May 4, 2006
Messages
112
Programming Experience
Beginner
I have a photo with a specific datapath. I need to delete the photo and replace it with another, retaining the same datapath. The picture to be saved is in a picturebox. In this code, I dispose the current pic in the picturebox, because if I dont, I cant delete it.....because it is in use. After that, I try to save the pic to the datapath, but I cannot because the picture was previously disposed, and I will get a null refernced. So, my question is...Is there a way to simply replace the first pic with the second pic while retaining the datapath? Or, is there a way to store the file and then save it, without interefering with the "This image is in use by another process"?
 

Attachments

  • what.jpg
    what.jpg
    84.8 KB · Views: 121
Sorry, what are you trying to do? Let me see if I've got this straight. You have an Image is a PictureBox that was loaded from a particular file. You want to replace that Image in the PictureBox with a different Image and then save that to the location of the original file. Is that correct?

Also, your profile says your main platform is VS.NET 2002 and yet that looks a lot like VS 2005 to me. If you're using a different version to what your profile says then it's a good idea to tell us so we can ensure that the advice given is for that version. Help us to help you. The more effort you put into making it as easy as possible for us to help you, the more likely you'll get useful advice.
 
this is what i think is going on

he's putting a picture from a file into a picturebox
he needs to save the picture from the picturebox to the file (same name and location) but he cant because the file's in use (from loading it in the first place)

so what he needs to do is:
VB.NET:
Dim Picture As Bitmap = PictureBox.Image
PictureBox.Image = Nothing
File.Delete(ImageLocation)
PictureBox.Image = Picture
PictureBox.Image.Save(ImageLocation)
and from the pic posted he is using VS2005, not 2002
 
Ok, this is very strange, and I am not sure what I should do, so I figured I better ask. I was trying to delete a file. Is is actually a photo from a file, and it was being displayed in a picturebox. I originally had trouble deleing it, because it was being used by another process...which was the fact it was being displayed in the picturebox. So, I used a code to dispose of the image before I tried to delete it. It was working great....then it started to pop up every now and then. I cannot see athing that it using the picture file, however....so what could be going on? Is there a better way to do this? This is the code here...but ignore that error..that was something else.
 

Attachments

  • what.jpg
    what.jpg
    84.8 KB · Views: 112
You still haven't clarified exactly what it is you're trying to do. I didn't ask that question for nothing. If you want to delete an image file that was displayed in a PictureBox then you need to sever the link between the Image object and the file. That means Disposing the Image object. If you want to keep the Image then you'll need to create a Clone and keep that. As for the best way to accomplish your overall goal, I couldn't say without knowing what that overall goal is. I'm quite sure that there's no need for you to be invoking the garbage collector, which it looks like you are.
 
I am sorry about that. The original problem I had was trying to delete an image and then replace it with another one while keeping the same path name. That is working great! I made a clone of it and eberything worked as I needed. Now, I have an area of code where I just want to completely delete the picture. I had trouble doing this because the picturebox was using it, it would not let me. So, I disposed of it, and everything was working great. BUT, for some odd reason it says it is in use by another process, but it rarely happens. I t is very sporatic. So, the dispose works fine, but every now and then it does it and I cant figre out why. Do you have any ideas? Sorry if I am not clear, I am new, Ian
 
Back
Top