using System; using System.Globalization; using System.Threading; using System.Threading.Tasks; namespace Brotli { internal class AsyncHelper { private static readonly TaskFactory _myTaskFactory = new TaskFactory(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default); internal static void RunSync(Func func, bool await = false) { CultureInfo cultureUi = CultureInfo.CurrentUICulture; CultureInfo culture = CultureInfo.CurrentCulture; _myTaskFactory.StartNew(delegate { Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = cultureUi; return func(); }).Unwrap().ConfigureAwait(await).GetAwaiter().GetResult(); } // Microsoft.AspNet.Identity.AsyncHelper internal static TResult RunSync(Func> func, bool await = false) { CultureInfo cultureUi = CultureInfo.CurrentUICulture; CultureInfo culture = CultureInfo.CurrentCulture; return _myTaskFactory.StartNew>(delegate { Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = cultureUi; return func(); }).Unwrap().ConfigureAwait(await).GetAwaiter().GetResult(); } internal static TResult RunSync(Func> func, object state, bool await = false) { CultureInfo cultureUi = CultureInfo.CurrentUICulture; CultureInfo culture = CultureInfo.CurrentCulture; return _myTaskFactory.StartNew>(delegate { Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = cultureUi; return func(state); }, state).Unwrap().ConfigureAwait(await).GetAwaiter().GetResult(); } internal static TResult RunSync(Func> func, object state, CancellationToken cancellationToken, bool await = false) { CultureInfo cultureUi = CultureInfo.CurrentUICulture; CultureInfo culture = CultureInfo.CurrentCulture; return _myTaskFactory.StartNew>(delegate { Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = cultureUi; return func(state); }, state, cancellationToken).Unwrap().ConfigureAwait(await).GetAwaiter().GetResult(); } } }