public static Bitmap DownloadImageCached(string url) => DownloadImageCachedWithExpiry(url, TimeSpan.FromDays(1000)); // image in cache is good forever. public static Bitmap DownloadImageCachedWithExpiry(string url, TimeSpan rotTime) { var fn = WebScraper.GetCachedFileNameFromUrl(url); if (File.Exists(fn) && File.GetLastWriteTime(fn).Add(rotTime) > DateTime.Now) { try { Debug.Write("c"); return(new Bitmap(fn)); } catch (Exception ex) { Debug.WriteLine(ex.Message + " - " + url, MethodInfo.GetCurrentMethod()?.DeclaringType.Name + "." + MethodInfo.GetCurrentMethod()?.Name); File.Delete(fn); // delete corrupt images } Debug.Write("?"); return(new Bitmap(5, 5)); } else { Debug.Write("n"); return(SaveWebImageToFile(url, fn)); } }