Browse Source

Better Semaphore fix

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

31
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.
@ -432,25 +430,20 @@ namespace ImageProcessor.Web.HttpModules
} }
} }
finally finally
{
// This should not happen :(
if (semaphore != null)
{ {
semaphore.Release(); 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);
@ -475,16 +468,12 @@ namespace ImageProcessor.Web.HttpModules
await cache.TrimCachedFolderAsync(cachedPath); await cache.TrimCachedFolderAsync(cachedPath);
} }
finally finally
{
// This should not happen :(
if (semaphore != null)
{ {
semaphore.Release(); semaphore.Release();
} }
} }
} }
} }
}
string incomingEtag = context.Request.Headers["If-None-Match"]; string incomingEtag = context.Request.Headers["If-None-Match"];

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