Ejemplo n.º 1
0
        public static async Task <long> BigSum()
        {
            List <Task <long> > tasks = new List <Task <long> >();

            foreach (var unused in Enumerable.Range(0, 5))
            {
                tasks.Add(CompletedTask.Get().CalcSomething());
            }

            try
            {
                var ret = await Task.WhenAll(tasks);

                return(ret.Sum());
            }
            catch (Exception e)
            {
                //If any task throws, WhenAll faults with the Exception here
                //There is no need to check exceptions from other tasks; first is enough
                Console.WriteLine(e);
                throw;
            }
        }