protected override void Dispose(bool disposing) { if (disposing) { DisposeComponents(); // RiftContext.Designer.cs if (gameProcessManager != null) { gameProcessManager.Dispose(); } if (serverManager != null) { serverManager.Dispose(); } if (shopManager != null) { shopManager.Dispose(); } if (imageCache != null) { imageCache.Dispose(); } } base.Dispose(disposing); }
private static void Exit() { Bot.Stop(); ImageCache.Dispose(); Log.CloseAndFlush(); }
//载入某个Illust的全部图片 private ImageCache Load(Illust illust) { {//hit ImageCache cache; if (cache_pool.TryGetValue(illust.id, out cache)) { cache.required_time = DateTime.UtcNow; return(cache); } } {//not hit ImageCache cache = new ImageCache(); cache.illust = illust; cache.required_time = DateTime.UtcNow; cache.data = new List <Image>(); for (int i = 0; i < illust.pageCount; i++) { if (illust.bookmarked && !illust.isPageValid(i)) { continue; } string path = String.Format("{0}/{1}", pixivClient.download_dir_main, illust.storeFileName(i)); if (File.Exists(path)) { try { var img = Image.FromFile(path); //我内存贼大,不用裁剪 img.Tag = i;//图片在illust中的原本index cache.data.Add(img); } catch (Exception e) { //视同文件损坏,删除 Console.WriteLine("Can't Load Image " + path); Console.WriteLine(e.Message); Console.WriteLine("Delete Image"); File.Delete(path); var img = (Image)empty_image.Clone(); img.Tag = -1; cache.data.Add(img); } } else { var img = (Image)empty_image.Clone(); img.Tag = -1; cache.data.Add(img); } } if (!cache_pool.TryAdd(illust.id, cache))//开头就检测过hit,如果此时已经存在,那肯定是刚加进去的,没必要更新required_time { cache.Dispose(); } while (cache_pool.Count > cache_size) { //C#里可修改的Pair类是什么? int oldest_cache = -1; DateTime oldest_cache_time = DateTime.MaxValue; foreach (var tmp_cache in cache_pool) { if (tmp_cache.Value.required_time < oldest_cache_time) { oldest_cache = tmp_cache.Key; oldest_cache_time = tmp_cache.Value.required_time; } } if (oldest_cache < 0) { continue; } ImageCache ignored; if (cache_pool.TryRemove(oldest_cache, out ignored)) { ignored.Dispose(); } } return(cache); } }