Share via


Error: The process cannot access the file 'image.jpg' because it is being used by another process.

Question

Saturday, May 8, 2010 6:27 AM

Hi,
i have a problem here.
I fetch an blob data from oracle db and set it to picture box , it works fine for the first loop but for the second i get an error

The process cannot access the file 'D:\workingfolder\myprj\bin\Debug\image.jpg' because it is being used by another process.

am actually using filestream to write into image and set it to picture box.
and then close the fs.close() and also set picturebox.image = null;

Any solution pls....

All replies (6)

Saturday, May 15, 2010 4:39 PM âś…Answered

Preferrably, this kind of error can be taken off with the help of -Using statement -

http://msdn.microsoft.com/en-us/library/yh598w02%28VS.80%29.aspx


Saturday, May 8, 2010 8:51 AM

pls add that code.

may be u forget to dispose the object thts why it is given this error.

you have to Dispose of the pb.image and the pb like this, where pb assumed picture box

 

pb.Image.Dispose();

pb.Dispose();


Monday, May 10, 2010 12:57 AM

Hi,

thanks for the reply..

and yes i have tried that also but i get another error saying

"Parameter is not valid." in my program.cs file.

pls can you clarify...


Monday, May 10, 2010 4:32 AM

can u pls debug the code. so u get the error and where its going wrong.

also post ur code. so i can understand it.


Monday, May 10, 2010 5:56 AM

Hi,

Here in my textbox txtempid in lostfocus event i fetch the details of the employee and put it in my dataset and then in controls.

For the first focuslost event occur it works fine but for the second time it gives me the error.

here is my code.

void txtempid_LostFocus(object sender, System.EventArgs e)
{
try
{

clearvalues();

DataSet empdtls = empbll.fetchempdtls(txtempid.Text); // fetch data from db and put it in //dataset

if (empdtls.Tables.Count > 0)
{
setexistingemps(empdtls);
}

}
catch (Exception ex)
{toolStripStatusLabel.Text = ex.Message;}
 }

private void setexistingemps(DataSet ods)
        {
            try
            {

//*****put data in all controls****

if (pbphoto.Image != null)
                {
                    //pbphoto.Image = null;
                    pbphoto.Image.Dispose();
                    //pbphoto.Refresh();
                }
                FileStream fs = new FileStream("image.jpg", FileMode.Open);
                byte[] img1 = (byte[])ods.Tables["ET_EMP_DTLS"].Rows[0]["AED_PHOTO"];
                fs.Write(img1, 0, img1.Length);
                fs.Close();
                fs.Dispose();
                //fs = null;
                pbphoto.Image = Image.FromFile("image.jpg");
                pbphoto.SizeMode = PictureBoxSizeMode.StretchImage;
                pbphoto.Refresh();

catch (Exception ex)
            { ods.Dispose();}
        }


Wednesday, August 10, 2011 6:42 AM

R u solve this error?

Plz tel me the solution for this error