oleksii
5/29/2017 - 10:29 PM

TaskExtensions.cs

using System.Threading.Tasks;

public static class TaskExtensions
{
    /// <summary>
    /// Synchronously awaits task throwing first exception if any instead of <see cref="System.AggregateException"/>.
    /// </summary>
    public static T Await<T>(this Task<T> task) => task.GetAwaiter().GetResult();

    /// <summary>
    /// Synchronously awaits task throwing first exception if any instead of <see cref="System.AggregateException"/>.
    /// </summary>
    public static void Await(this Task task) => task.GetAwaiter().GetResult();
}