Skip to content

Commit fa202b6

Browse files
authored
Fix create BitmapDecoder with async file stream. (#4966)
* Fix create BitmapDecoder with async file stream. [BitmapDecoder.Create does not handle FileStream with FileOptions.Asynchronous · Issue #4355 · dotnet/wpf](#4355 ) * Add comment
1 parent a3901c0 commit fa202b6

File tree

1 file changed

+10
-2
lines changed
  • src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging

1 file changed

+10
-2
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,14 +1138,22 @@ out SafeFileHandle safeFilehandle
11381138
if (stream is System.IO.FileStream)
11391139
{
11401140
System.IO.FileStream filestream = stream as System.IO.FileStream;
1141-
11421141
try
11431142
{
1144-
safeFilehandle = filestream.SafeFileHandle;
1143+
if (filestream.IsAsync is false)
1144+
{
1145+
safeFilehandle = filestream.SafeFileHandle;
1146+
}
1147+
else
1148+
{
1149+
// The IWICImagingFactory_CreateDecoderFromFileHandle_Proxy do not support async Filestream, so we revert to old code path.
1150+
safeFilehandle = null;
1151+
}
11451152
}
11461153
catch
11471154
{
11481155
// If Filestream doesn't support SafeHandle then revert to old code path.
1156+
// See https://github.com/dotnet/wpf/issues/4355
11491157
safeFilehandle = null;
11501158
}
11511159
}

0 commit comments

Comments
 (0)