public RangeRequestInfo(RangedQueryIndivisualResultCallback handler) { this.handler = handler; this.IsCancelled = false; }
public static async void StartRequestImagePathForCalendar(IEnumerable<DateTime> list, RangedQueryIndivisualResultCallback handler) { if (list == null) throw new ArgumentNullException("list"); if (handler == null) throw new ArgumentNullException("handler"); var currentRangeInfo = _currentRangeRequestInfo; if (currentRangeInfo != null) currentRangeInfo.StopTasks(); _currentRangeRequestInfo = currentRangeInfo = new RangeRequestInfo(handler); DateTime maxTime = DateTime.MinValue, minTime = DateTime.MaxValue; foreach (var item in list) { if (maxTime < item.Date) maxTime = item.Date; if (minTime > item.Date) minTime = item.Date; } var infos = await _readonlyStore.ReadImageInfosAsync(minTime, maxTime); if (infos != null) { var llist = new LinkedList<Task>(); for (int i = 0; i < infos.Length; i++) { var info = infos[i]; llist.AddLast(Task.Run(async () => await RequestImagePathForCalendarStartRequestAsync(info, currentRangeInfo))); if (llist.Count == 9) { // limit to 9 running at the same time await Task.WhenAny(llist); var walker = llist.First; while (walker != null) { if (walker.Value.IsCompleted) { var marked = walker; walker = walker.Next; llist.Remove(marked); } else walker = walker.Next; } } } llist.Clear(); // don't care about thread endstats; } }