TPL: Exception.Flatten().InnerExceptions.ForEachInEnumerable

Coordinator
Apr 3, 2012 at 1:41 AM
Edited Apr 3, 2012 at 1:42 AM

 

        /// <summary>
        /// Gets the solar energy reading.
        /// </summary>
        [Invoke]
        public SolarEnergyReading GetSolarEnergyReading()
        {
            var model = new SolarEnergyReading();
            var uri = new Uri("xxx");
            var wait = HttpVerbAsyncUtility.GetAsync(uri)
                .ContinueWith(
                t =>
                {
                    if (t.IsFaulted)
                        t.Exception.Flatten().InnerExceptions.ForEachInEnumerable(
                        i =>
                        {
                            Debug.WriteLine("GetSolarEnergyReading Exception(s): {0}", i.Message);
                        });
                    if (t.IsCompleted && !t.IsFaulted)
                        model = SolarEnergyModelContext.GetSolarEnergyReading(t.Result);
                })
                .Wait(TimeSpan.FromSeconds(7));
            return model;
        }