Skip to content

Instantly share code, notes, and snippets.

Created May 6, 2014 19:19
Show Gist options
  • Save anonymous/ec2a02e7d2e6011074be to your computer and use it in GitHub Desktop.
Save anonymous/ec2a02e7d2e6011074be to your computer and use it in GitHub Desktop.
Execute async method synchronously
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