Home All Groups Group Topic Archive Search About

Can't move tif file after reading it to picturebox

Author
10 Apr 2006 1:20 PM
yoav
Hi Folks,

The following code crashes on the last statement with a "The process
cannot access the file because it is being used by another process"
exception (fiFax is a FileInfo object):

            Dim picbox As New PictureBox
            picbox.Image = Drawing.Image.FromFile(fiFax.FullName)
            picbox.Dispose()
            fiFax.MoveTo(fiFax.Directory.FullName & "\Old\" &
fiFax.Name)    ' Exception!!!

If I put the "fiFax.MoveTo" statement before the "FromFile" it works.
Why does the picturebox keeps the file locked even after it is
disposed? How can I release it?

TIA

Author
10 Apr 2006 5:35 PM
Michael D. Ober
This appears to be a bug in the Windows API itself.  The workaround is to
create a dummy tif image and load it into the picbox before attempting to
move the original image.  I have the same problem in one of my older
programs that uses the Kodak Image OCX drivers.

Mike Ober

"yoav" <yoav.benyo***@gmail.com> wrote in message
news:1144675234.547382.176250@z34g2000cwc.googlegroups.com...
> Hi Folks,
>
> The following code crashes on the last statement with a "The process
> cannot access the file because it is being used by another process"
> exception (fiFax is a FileInfo object):
>
>             Dim picbox As New PictureBox
>             picbox.Image = Drawing.Image.FromFile(fiFax.FullName)
>             picbox.Dispose()

picbox.Image = new Drawing.Image

or

picbox.Image = Drawing.Image.FromFile("dummy.tif")

Show quote
>             fiFax.MoveTo(fiFax.Directory.FullName & "\Old\" &
> fiFax.Name)    ' Exception!!!
>
> If I put the "fiFax.MoveTo" statement before the "FromFile" it works.
> Why does the picturebox keeps the file locked even after it is
> disposed? How can I release it?
>
> TIA
>
>
Author
11 Apr 2006 6:24 AM
yoav
Hi Mike,

I tried your suggestion but the file was still locked. However, I
solved it using:

          picbox.Image.Dispose()

before attempting to move the file.

Thanks


Michael D. Ober wrote:
Show quote
> This appears to be a bug in the Windows API itself.  The workaround is to
> create a dummy tif image and load it into the picbox before attempting to
> move the original image.  I have the same problem in one of my older
> programs that uses the Kodak Image OCX drivers.
>
> Mike Ober
>
> "yoav" <yoav.benyo***@gmail.com> wrote in message
> news:1144675234.547382.176250@z34g2000cwc.googlegroups.com...
> > Hi Folks,
> >
> > The following code crashes on the last statement with a "The process
> > cannot access the file because it is being used by another process"
> > exception (fiFax is a FileInfo object):
> >
> >             Dim picbox As New PictureBox
> >             picbox.Image = Drawing.Image.FromFile(fiFax.FullName)
> >             picbox.Dispose()
>
> picbox.Image = new Drawing.Image
>
> or
>
> picbox.Image = Drawing.Image.FromFile("dummy.tif")
>
> >             fiFax.MoveTo(fiFax.Directory.FullName & "\Old\" &
> > fiFax.Name)    ' Exception!!!
> >
> > If I put the "fiFax.MoveTo" statement before the "FromFile" it works.
> > Why does the picturebox keeps the file locked even after it is
> > disposed? How can I release it?
> >
> > TIA
> >
> >

AddThis Social Bookmark Button