Created
May 6, 2014 19:19
-
-
Save anonymous/ec2a02e7d2e6011074be to your computer and use it in GitHub Desktop.
Execute async method synchronously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static class AsyncHelper { | |
private static readonly TaskFactory taskFactory = new TaskFactory(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default); | |
public static TResult RunSync<TResult>(Func<Task<TResult>> func) { | |
return taskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult(); | |
} | |
public static void RunSync(Func<Task> func) { | |
taskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment