public void HitomiSearch() { List <int> idlist = new List <int>(); int compcount = 0; if (cache.Keys.Any(x => x.ItemsEqual(tags))) { string[] key = cache.Keys.Where(x => x.ItemsEqual(tags)).First(); this.start(0); idlist = cache[key].ToList(); compcount = tags.Length; } else { List <Task> tasks = new List <Task>(); this.start(tags.Length); Dispatcher dispatcher = Dispatcher.CurrentDispatcher; foreach (string tag in tags) { Hitomi.HTag tag2 = Hitomi.HTag.Parse(tag); string path = Path.Combine(Global.rootDir, "Cache", tag2.type, tag2.tag + ".json"); if (Global.config.cache_search.Get <bool>()) { if (File.Exists(path)) { JArray arr = JArray.Parse(File.ReadAllText(path)); int[] ids = arr.Select(x => int.Parse(x.ToString())).ToArray(); idlist = idlist.Concat(ids).ToList(); compcount++; continue; } } Thread th = new Thread(new ThreadStart(async() => { int[] ids; InternetP parser = new InternetP(); parser.index = index - 1; parser.Count = search_count; if (HiyobiTags.Tags.Select(y => y.full).Contains(tag)) { try { ids = parser.ByteArrayToIntArrayBig(await parser.LoadNozomiTag(tag2.type.ToString(), tag2.tag, range: !Global.config.cache_search.Get <bool>(), start: 0, end: 99)); } catch { ids = new int[0]; } } else { ids = await parser.LoadQuery(tag); } if (Global.config.cache_search.Get <bool>() && !File.Exists(path)) { if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } File.WriteAllText(path, JArray.FromObject(ids).ToString()); } dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => idlist = idlist.Concat(ids).ToList())); compcount++; dispatcher.Invoke(() => update(compcount, tags.Length)); })); th.Start(); } } int start = (index - 1) * itemCount; int PageCount = start + itemCount; Task.Factory.StartNew(() => { while (compcount != tags.Length) { } if (!cache.Keys.Any(x => x.ItemsEqual(tags))) { cache.Add(tags, idlist.ToArray()); } List <int> new_idlist = new List <int>(); for (int i = 0; i < idlist.Count; i++) { int count = idlist.Count(y => y == idlist[i]); if (count == tags.Length) { new_idlist.Add(idlist[i]); } if (new_idlist.Count >= PageCount) { break; } } new_idlist = new_idlist.Skip(start).ToList(); Global.dispatcher.Invoke(delegate { HitomiLoader hitomi = new HitomiLoader(); hitomi.Default(); LoaderDefaults.Hitomis.Setup(hitomi); hitomi.Parser(new_idlist.ToArray()); }); }); }