Skip to content

Instantly share code, notes, and snippets.

@dimonovdd
Created May 23, 2021 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimonovdd/e9370f204ef45aa1777dad7d6ccab665 to your computer and use it in GitHub Desktop.
Save dimonovdd/e9370f204ef45aa1777dad7d6ccab665 to your computer and use it in GitHub Desktop.
RunSyncUtil
using System;
using System.Threading.Tasks;
namespace Sync
{
public static class RunSyncUtil
{
private static readonly TaskFactory factory = new
TaskFactory(default,
TaskCreationOptions.None,
TaskContinuationOptions.None,
TaskScheduler.Default);
public static T1 RunSync<T1>(Func<Task<T1>> task)
=> factory.StartNew(task).Unwrap().GetAwaiter().GetResult();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment