Quantcast
Channel: HTML Renderer
Viewing all articles
Browse latest Browse all 693

Commented Unassigned: Loaded images lock source file until component disposed [9038]

$
0
0
Hello,

This is a follow on bug I found whilst investigating [this one](https://htmlrenderer.codeplex.com/workitem/9037). The sample project I attached to that issue can also be used to repro this one.

Apologies but I haven't dug through the code to find the exact cause, or indeed to raise a pull request with a fix.

I assume you are using the standard `Image.FromFile` method or similar to load a source image. The problem with this approach is that it [actually locks the source file](http://stackoverflow.com/a/3845491/148962), so that you cannot modify it or delete it etc.

If you open up the demo project I provided in the other issue, you can see I copy a source image to a temporary file, and use that in the HTML for the control. Then, in `OnFormClosing` I attempt to clean up by deleting the temp file. In this method you'll notice I have a call to `htmlPanel.Dispose`. If you remove this call, you'll then find that the `File.Delete` call will crash as the file is in use.

I tend to work around this by creating a copy of the image, that way I can dispose of the original image, thus releasing the file in case I want to save over it, or delete it, and so on. Then I just ensure I dispose of the copy as usual.

Regards;
Richard Moss

Comments: I know of it but it is not a bug but a way .NET loads images where if the image is formatted in some way the original stream must be available at later point. If you are 100% sure your images do not suffer from this issue you can override the image loading using ImageLoad event and load the image yourself. Hope it help, Cheers.

Viewing all articles
Browse latest Browse all 693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>