BUG: System.Drawing.Image.FromFile locks file

T

Taiwo

When I use the method "System.Drawing.Image.FromFile(pictureFile)" where
pictureFile is the path to a valid image file, the file is locked even
minutes after the statement executes. This code is in a web service hosted
in IIS on Windows XP. Typically, I have to run IISRESET from the Command
Line to be able to rename the file.

My work around is to use a different method:

Dim fs As FileStream = New FileStream(pictureFile, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)
dim pic As Image = System.Drawing.Image.FromStream(fs)
fs.Close()
fs = Nothing

With this method, I open the file for Read Shared, use the FromStream
method, and close the file stream immediately.

The VS.NET team here may want to verify this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top