From a454aeeb4d0059fffd5783c2caa897e6ded2f368 Mon Sep 17 00:00:00 2001 From: James South Date: Thu, 5 Dec 2013 13:56:52 +0000 Subject: [PATCH] Making the save method a little more robust Former-commit-id: 439b084d1c9224e1154a8aee67b7dd706fe29e79 --- src/ImageProcessor/ImageFactory.cs | 31 ++++++++++++++++--- .../Test_Website_NET45.csproj | 4 ++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 5092cfab3..a25f31878 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -18,6 +18,8 @@ namespace ImageProcessor using System.Drawing.Imaging; using System.IO; using System.Linq; + using System.Threading; + using ImageProcessor.Imaging; using ImageProcessor.Processors; #endregion @@ -683,18 +685,39 @@ namespace ImageProcessor { ImageCodecInfo imageCodecInfo = ImageCodecInfo.GetImageEncoders() - .FirstOrDefault( - ici => ici.MimeType.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase)); + .FirstOrDefault(ici => ici.MimeType.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase)); if (imageCodecInfo != null) { - this.Image.Save(filePath, imageCodecInfo, encoderParameters); + for (int i = 0; i < 3; i++) + { + try + { + this.Image.Save(filePath, imageCodecInfo, encoderParameters); + break; + } + catch (IOException) + { + Thread.Sleep(200); + } + } } } } else { - this.Image.Save(filePath, this.ImageFormat); + for (int i = 0; i < 3; i++) + { + try + { + this.Image.Save(filePath, this.ImageFormat); + break; + } + catch (IOException) + { + Thread.Sleep(200); + } + } } } diff --git a/src/TestWebsites/NET45/Test_Website_NET45/Test_Website_NET45.csproj b/src/TestWebsites/NET45/Test_Website_NET45/Test_Website_NET45.csproj index a041c692a..318733563 100644 --- a/src/TestWebsites/NET45/Test_Website_NET45/Test_Website_NET45.csproj +++ b/src/TestWebsites/NET45/Test_Website_NET45/Test_Website_NET45.csproj @@ -188,7 +188,9 @@ - + + Designer +