From 8640c5a69f85f6593cf1a4031fd517daf2cdefc0 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: 0cb4f998dda6221477d30d5b6cd1935eedfced5b --- 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 5092cfab3c..a25f31878d 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 a041c692af..3187335630 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 +