Running an async function synchronously
public static class TaskExtensions
{
    private static readonly TaskFactory TaskFactory = new TaskFactory(
            CancellationToken.None, 
            TaskCreationOptions.None, 
            TaskContinuationOptions.None, 
            TaskScheduler.Default);

    public static TResult RunSync&lt;TResult&gt;(this Func&lt;Task&lt;TResult&gt;&gt; asyncFunc)
        =&gt; TaskFactory
            .StartNew(asyncFunc)
            .Unwrap()
            .GetAwaiter()
            .GetResult();

    public static void RunSync(this Func&lt;Task&gt; asyncAction)
        =&gt; TaskFactory
            .StartNew(asyncAction)
            .Unwrap()
            .GetAwaiter()
            .GetResult();
}


There are several things that worth mentioning:  


Async methods were designed to be used all the way. So, if you call an async I/O operation in the bottom layer then it should be be called in an async fashion till the top layer.
Async operations are sensitive for Exceptions. They can behave differently based on how you call them. (They can be swallowed, thrown as an AggregateException or thrown normally. Here the UnWrap + GetAwaiter do the magic for us to be able to handle the exception normally.  
In order to avoid deadlocks the async operation is passed to an other Task, that is where TaskFactory.StartNew comes into play.