PC Review


Reply
Thread Tools Rate Thread

BitmapDecoder not releasing file lock

 
 
Roger Martin
Guest
Posts: n/a
 
      19th May 2008
I am having an issue related to my original thread here:

http://www.microsoft.com/communities...=en-us&m=1&p=1

In that thread you helped me figure out how to ensure that the BitmapDecoder
releases the file lock. I have discovered that, while it CORRECTLY releases
the file lock when a valid image is passed to the BitmapDecoder.Create()
method, it DOES NOT release the lock when the method throws an exception.

Specifically, certain images, such as WMF files, throw an exception when
passed to the Create() method. When this occurs, the file lock is not
released. When this happens in my web application, I am unable to delete the
file unless I cycle the app pool or call GC.Collect.

Here is code to reproduce:

using System;
using System.Windows.Media.Imaging;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string imageFilePath = @"D:\BD00146_.WMF";
BitmapMetadata bmp = GetBitmapMetadata(imageFilePath);
}

private static BitmapMetadata GetBitmapMetadata(string imageFilePath)
{
BitmapDecoder fileBitmapDecoder;
try
{
fileBitmapDecoder = BitmapDecoder.Create(new Uri(imageFilePath,
UriKind.Absolute), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
}
catch (NotSupportedException)
{
// Lock is not released unless I perform a garbage collection.
//GC.Collect();
return null;
}

return null;
}
}
}

Note: The file lock will occur on any file that generates an exception. If
you can't find a WMF file for testing, you can use a plain text file.

It is impossible to accurately predict which files will end up throwing an
exception, so I need the Create method to release the lock on its own or I
need a way to release the file lock within the catch block. Since the
exception will rarely occur, the only solution may be to run the garbage
collector in the catch block, but I don't think this is the best practice
recommended by MS.

If you determine this is a bug, can you create the appropriate paperwork so
that it might be fixed or tell me where I should submit it?

Cheers,
Roger Martin
Gallery Server Pro - Open Source Web App for Photos, Video, Audio and
Documents
www.galleryserverpro.com
 
Reply With Quote
 
 
 
 
Roger Martin
Guest
Posts: n/a
 
      19th May 2008
Thanks, Pete. I tried your suggestion of using a FileStream and it worked!
Thanks.

Meanwhile, I create a bug report at
https://connect.microsoft.com/Visual...dbackID=344914.

Cheers,
Roger
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Supported image-formats by Windows.Media.BitmapDecoder? Johann Löwen Microsoft Dot NET Framework 4 6th Oct 2009 12:24 AM
Releasing recordset lock =?Utf-8?B?U1RV?= Microsoft Access VBA Modules 4 16th Jul 2007 03:38 PM
BitmapDecoder not releasing file lock =?Utf-8?B?Um9nZXIgTWFydGlu?= Microsoft Dot NET Framework 3 14th Feb 2007 02:25 PM
Releasing lock on a text file? David Veeneman Microsoft ASP .NET 4 12th Feb 2007 02:54 AM
Releasing a file John Wright Microsoft Dot NET 1 20th May 2006 08:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:16 AM.