Browse Source

Better Semaphore fix

Former-commit-id: c679e15305cade71e0fec7d3db7f0eab41224741
pull/17/head
James South 12 years ago
parent
commit
b0d194c931
  1. 35
      src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
  2. 2
      src/ImageProcessor/Imaging/Formats/GifFormat.cs
  3. 8
      src/TestWebsites/NET45/Test_Website_NET45/Web.config

35
src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs

@ -385,16 +385,14 @@ namespace ImageProcessor.Web.HttpModules
if (isRemote) if (isRemote)
{ {
SemaphoreSlim semaphore = GetSemaphoreSlim(cachedPath); SemaphoreSlim semaphore = GetSemaphoreSlim(cachedPath);
#if NET45
await semaphore.WaitAsync();
#else
semaphore.Wait();
#endif
try try
{ {
// This should not happen :(
if (semaphore != null)
{
semaphore.Wait();
}
Uri uri = new Uri(requestPath + "?" + urlParameters); Uri uri = new Uri(requestPath + "?" + urlParameters);
RemoteFile remoteFile = new RemoteFile(uri, false); RemoteFile remoteFile = new RemoteFile(uri, false);
// Prevent response blocking. // Prevent response blocking.
@ -433,24 +431,19 @@ namespace ImageProcessor.Web.HttpModules
} }
finally finally
{ {
// This should not happen :( semaphore.Release();
if (semaphore != null)
{
semaphore.Release();
}
} }
} }
else else
{ {
SemaphoreSlim semaphore = GetSemaphoreSlim(cachedPath); SemaphoreSlim semaphore = GetSemaphoreSlim(cachedPath);
#if NET45
await semaphore.WaitAsync();
#else
semaphore.Wait();
#endif
try try
{ {
// This should not happen :(
if (semaphore != null)
{
semaphore.Wait();
}
// Check to see if the file exists. // Check to see if the file exists.
// ReSharper disable once AssignNullToNotNullAttribute // ReSharper disable once AssignNullToNotNullAttribute
FileInfo fileInfo = new FileInfo(requestPath); FileInfo fileInfo = new FileInfo(requestPath);
@ -476,11 +469,7 @@ namespace ImageProcessor.Web.HttpModules
} }
finally finally
{ {
// This should not happen :( semaphore.Release();
if (semaphore != null)
{
semaphore.Release();
}
} }
} }
} }

2
src/ImageProcessor/Imaging/Formats/GifFormat.cs

@ -86,7 +86,7 @@ namespace ImageProcessor.Imaging.Formats
foreach (GifFrame frame in info.GifFrames) foreach (GifFrame frame in info.GifFrames)
{ {
factory.Image = frame.Image; factory.Image = frame.Image;
frame.Image = quantizer.Quantize(processor.Invoke(factory)); frame.Image = quantizer.Quantize(processor.Invoke(factory));
encoder.AddFrame(frame); encoder.AddFrame(frame);
} }
} }

8
src/TestWebsites/NET45/Test_Website_NET45/Web.config

@ -6,17 +6,17 @@
<configuration> <configuration>
<configSections> <configSections>
<!--<sectionGroup name="imageProcessor"> <sectionGroup name="imageProcessor">
<section name="security" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageSecuritySection, ImageProcessor.Web"/> <section name="security" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageSecuritySection, ImageProcessor.Web"/>
<section name="processing" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageProcessingSection, ImageProcessor.Web"/> <section name="processing" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageProcessingSection, ImageProcessor.Web"/>
<section name="cache" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageCacheSection, ImageProcessor.Web"/> <section name="cache" requirePermission="false" type="ImageProcessor.Web.Configuration.ImageCacheSection, ImageProcessor.Web"/>
</sectionGroup>--> </sectionGroup>
</configSections> </configSections>
<!--<imageProcessor > <imageProcessor >
<security configSource="config\imageprocessor\security.config"/> <security configSource="config\imageprocessor\security.config"/>
<cache configSource="config\imageprocessor\cache.config"/> <cache configSource="config\imageprocessor\cache.config"/>
<processing configSource="config\imageprocessor\processing.config"/> <processing configSource="config\imageprocessor\processing.config"/>
</imageProcessor>--> </imageProcessor>
<appSettings> <appSettings>
<add key="webpages:Version" value="2.0.0.0" /> <add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" /> <add key="webpages:Enabled" value="false" />

Loading…
Cancel
Save