G
gerardianlewis
Any help appreciated.
(VB.NET under XP and Vista, SP1 installed)
My code, inherited from a VB6 version of an app that ran under W98,
loads an image from a file into a PictureBox. The user may want to
move or delete the file that is being shown. The corresponding event-
driven code for "delete this picture" uses:
My.Computer.FileSystem.DeleteFile(sPath)
The exception which is thrown tells me that the system cannot access
the file as it's "being used by another process". What other process?
(There is no multithreading in the app.) Presumably this means that
you can't do anything with a jpg image file while it's being displayed
in a PictureBox (whereas you could with VB6/W98). Annoying, but I
decided on a workaround that meant blanking out the PictureBox before
attempting to delete the file. I've experimented with several methods,
including loading a new image from a different (dummy) jpg file,
setting the Image property to a bitmap created on the fly, or just
doing this before the delete:
frmMainForm.picPreview.Image.Dispose()
Still no luck - or rather, sometimes the deletion takes place without
problems, but most of the time it throws an exception, and if you loop
around and try again and again for a minute or two, usually the
exceptions just keep on coming. Still more mysteriously, tests suggest
that the system finally frees up the image file for deletion after a
few seconds in some cases (counting from where the PictureBox is
loaded with another image), or after a few minutes in others.
Can anyone figure out what's going on?
(I know that in theory you could dispense with the PictureBox
completely and just display the image using GDI+ graphics methods on
the form surface, but there are various reasons why implementing such
a solution would be hugely time-consuming for this app.)
(VB.NET under XP and Vista, SP1 installed)
My code, inherited from a VB6 version of an app that ran under W98,
loads an image from a file into a PictureBox. The user may want to
move or delete the file that is being shown. The corresponding event-
driven code for "delete this picture" uses:
My.Computer.FileSystem.DeleteFile(sPath)
The exception which is thrown tells me that the system cannot access
the file as it's "being used by another process". What other process?
(There is no multithreading in the app.) Presumably this means that
you can't do anything with a jpg image file while it's being displayed
in a PictureBox (whereas you could with VB6/W98). Annoying, but I
decided on a workaround that meant blanking out the PictureBox before
attempting to delete the file. I've experimented with several methods,
including loading a new image from a different (dummy) jpg file,
setting the Image property to a bitmap created on the fly, or just
doing this before the delete:
frmMainForm.picPreview.Image.Dispose()
Still no luck - or rather, sometimes the deletion takes place without
problems, but most of the time it throws an exception, and if you loop
around and try again and again for a minute or two, usually the
exceptions just keep on coming. Still more mysteriously, tests suggest
that the system finally frees up the image file for deletion after a
few seconds in some cases (counting from where the PictureBox is
loaded with another image), or after a few minutes in others.
Can anyone figure out what's going on?
(I know that in theory you could dispense with the PictureBox
completely and just display the image using GDI+ graphics methods on
the form surface, but there are various reasons why implementing such
a solution would be hugely time-consuming for this app.)