public async Task <Updates> Updates(ISession session) { try { Updates upds = new Updates(); upds.Items = new List <Episode>(); if (!UpdateHistory.IsLoaded) { UpdateHistory.Load(); } DaiSukiSession s = session as DaiSukiSession; if (s == null) { return new Updates { ErrorMessage = "Invalid Session", Status = ResponseStatus.InvalidArgument } } ; Shows sws = await Shows(s, false); if (sws.Status != ResponseStatus.Ok) { Updates k = new Updates(); sws.PropagateError(k); return(k); } int cnt = Convert.ToInt32(GetAuthSetting(DaiSukiPluginInfo.MaxFollowItems)); List <Show> avs = sws.Items.Take(cnt).ToList(); List <Task <Episodes> > ms = new List <Task <Episodes> >(); foreach (Show sh in avs) { ms.Add(Episodes(s, sh)); } string datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); if (ms.Count > 0) { while (ms.Count > 0) { int max = 5; if (ms.Count < 5) { max = ms.Count; } Task <Episodes>[] tsks = new Task <Episodes> [max]; for (int x = 0; x < max; x++) { tsks[x] = ms[0]; ms.Remove(ms[0]); } await Task.WhenAll(tsks); for (int x = max - 1; x >= 0; x--) { if (tsks[x].Result != null) { if (tsks[x].Result.Items.Count > 0) { Episode ep = tsks[x].Result.Items.OrderByDescending(a => a.Index).First(); ep.UniqueTag = DaiSukiPluginInfo.PluginName + "|" + ep.ShowName + "|" + ep.EpisodeAlpha; if (UpdateHistory.Exists(ep.UniqueTag)) { Episode c = JsonConvert.DeserializeObject <Episode>(UpdateHistory.Get(ep.UniqueTag)); upds.Items.Add(c); } else { ep.DateTime = datetime; UpdateHistory.Add(ep.UniqueTag, JsonConvert.SerializeObject(ep)); upds.Items.Add(ep); } } } } } UpdateHistory.Save(); } return(upds); } catch (Exception e) { return(new Updates { ErrorMessage = e.ToString(), Status = ResponseStatus.SystemError }); } }