Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jbogard/889ea1bdd30e0bf7a18f to your computer and use it in GitHub Desktop.
Save jbogard/889ea1bdd30e0bf7a18f to your computer and use it in GitHub Desktop.
internal static class AsyncHelper {
private static readonly TaskFactory taskFactory = new TaskFactory(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default);
public static TResult RunSync<TResult>(this Func<Task<TResult>> func) {
return taskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult();
}
public static void RunSync(this 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