Wednesday 16 November 2016

.Net High Performance Part 3 :Yield the Result from First Task in set of tasks

One quick thing before I forget this method. If there are multiple Tasks which are executing in parallel, how to yield the result from the first one to finish ?

It is simple as stack them into an array and waiting to until the first one to finish. Following is the coding.

 

 Task tasks = {t1,t2,t3...}; // The Task Array 

 int index = tasks.WaitAny(tasks);

 return tasks[index].Result;



No comments:

Post a Comment