private void PosterCacheAdd(string fullFilePath, Image image) { try { lock (posterCacheLock) { FileEntryImage fileEntryImage = new FileEntryImage(fullFilePath, FileHandler.GetLastWriteTime(fullFilePath), new Bitmap(image)); //new new Bitmap to make it thraadsafe https://stackoverflow.com/questions/49679693/c-sharp-crashes-with-parameter-is-not-valid-when-setting-picturebox-image-to posterCache.Add(fileEntryImage); //Add last if (posterCache.Count > 10) { posterCache.RemoveAt(0); //Only remember last x images } } } catch (Exception ex) { Logger.Error(ex, "PosterCacheAdd"); } }
private Image PosterCacheRead(string fullFileName) { Image image = null; try { int indexFound = -1; FileEntry fileEntry = new FileEntry(fullFileName, FileHandler.GetLastWriteTime(fullFileName, waitAndRetry: false)); lock (posterCacheLock) { for (int index = 0; index < posterCache.Count; index++) { if (posterCache[index] == fileEntry) { indexFound = index; break; } } if (indexFound > -1) { //new new Bitmap to make it thraadsafe https://stackoverflow.com/questions/49679693/c-sharp-crashes-with-parameter-is-not-valid-when-setting-picturebox-image-to FileEntryImage fileEntryImage = new FileEntryImage(posterCache[indexFound].FileEntry, posterCache[indexFound].Image); posterCache.Add(fileEntryImage); //Add last posterCache.RemoveAt(indexFound); image = new Bitmap(posterCache[posterCache.Count - 1].Image); } } } catch (Exception ex) { Logger.Error(ex, "PosterCacheRead"); } return(image); }