Wednesday 16 November 2016

.Net High Performance Part 4 : WaitAllOneByOne Pattern

There is an interesting design pattern with .Net Parallel Task processing called "WaitAllOneByOne". As the name implies, it is waiting for all Tasks to complete and process the results as in the order of Tasks are completed. Following is the coding.


 

// Create a list of Tasks 
List> tasks = new List>();
  
// Create N number of tasks 
for(int i=0;i(//Code for task goes here));

while(tasks.Count>0)
{
  int index = Task.WaitAny(tasks.ToArray());

  // process tasks[index].Result;

  tasks.RemoveAt(index);
} 




No comments:

Post a Comment