zoukankan      html  css  js  c++  java
  • 在同步中调用异步方法[.net 4.5]

    using System;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace Microsoft.AspNet.Identity
    {
        internal static class AsyncHelper
        {
            private static readonly TaskFactory _myTaskFactory = new TaskFactory(CancellationToken.None,
                TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default);
    
            public static TResult RunSync<TResult>(Func<Task<TResult>> func)
            {
                return _myTaskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult();
            }
    
            public static void RunSync(Func<Task> func)
            {
                _myTaskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult();
            }
        }
    }
  • 相关阅读:
    bzoj1648
    bzoj3404
    bzoj1650
    bzoj1625
    bzoj1606
    bzoj1464
    bzoj1572
    bzoj1617
    bzoj1092
    bzoj1091
  • 原文地址:https://www.cnblogs.com/zbw911/p/3907672.html
Copyright © 2011-2022 走看看