Consultor Eletrônico



Kbase P169437: Cannot delete image file with OS-DELETE when used in a PictureBox.Image
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   08/07/2010
Status: Unverified

SYMPTOM(s):

Cannot delete image file with OS-DELETE when used in a PictureBox.Image

OS-DELETE returns errno 2 when attempting to delete an image file used in a System.Drawing.Image

FACT(s) (Environment):

Windows
OpenEdge 10.2x
OpenEdge Category: Language (4GL/ABL)

CAUSE:

When loading an image from a file in .NET components that image is locked until the image is unloaded or the object is disposed, and that disposal may not actually occur until the object is actually garbage collected.

FIX:

If you need to delete the file associated with the image after displaying it, it is best to use a FileStream object to load the image into memory using a System.Drawing.Bitmap object, then close stream and dispose of the interim Image object.

e.g.
oFileMode = System.IO.FileMode:Open.
oFileStream = NEW System.IO.FileStream(cFileName,oFileMode).
oOriginal = System.Drawing.Image:FromStream(oFileStream).
oBitmap = NEW System.Drawing.Bitmap(oOriginal).
oFileStream:Close().
oOriginal:Dispose().

THIS-OBJECT:ultraPictureBox1:IMAGE = oBitmap.
OS-DELETE VALUE(cFileName) NO-ERROR.