public static void RunSync(Func<Task> fn) => Task.Run(fn).ConfigureAwait(false).GetAwaiter().GetResult(); public static T RunSync<T>(Func<Task<T>> fn) => Task.Run(fn).ConfigureAwait(false).GetAwaiter().GetResult(); // an async main: static void Main(string[] args) { var result = RunSync(() => MainAsync()); Console.ReadKey(); }
192100cookie-checkC# Run async task in sync task (and wait for it)