Guest User

Untitled

a guest
Jan 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. WorkloadManager.Instance.Add(Subscriptions.Instance.Dictionary.Count);
  2.  
  3. int i = 0;
  4. var tasks = new Task[Subscriptions.Instance.Dictionary.Count];
  5.  
  6. foreach (var pair in this._feeds)
  7. {
  8. var feed = pair.Value;
  9. feed.OnStateChange += UpdateState;
  10. tasks[i] = Task.Factory.StartNew(() => TaskProcessFeed(feed));
  11. i++;
  12. }
  13.  
  14. var tasksWaitQueue = tasks;
  15.  
  16. while (tasksWaitQueue.Length > 0)
  17. {
  18. int taskIndex = Task.WaitAny(tasksWaitQueue);
  19. tasksWaitQueue = tasksWaitQueue.Where((t) => t != tasksWaitQueue[taskIndex]).ToArray();
  20. WorkloadManager.Instance.Step();
  21. }
  22.  
  23. try { Task.WaitAll(tasks); }
  24. catch (AggregateException aggregateException)
  25. {
  26. foreach (var exception in aggregateException.InnerExceptions)
  27. {
  28. Logger.ErrorException(exception, "One of the tasks failed.");
  29. }
  30. }
Add Comment
Please, Sign In to add comment