Exemplo n.º 1
0
        /// <summary>
        ///     关闭
        /// </summary>
        public static async Task Shutdown()
        {
            if (ZeroAppOption.Instance.ApplicationState >= StationState.Closing)
            {
                return;
            }
            DateTime start = DateTime.Now;
            double   sec;
            int      cnt = 0;;

            Logger.Information($"【等待结束】剩余请求数:({ZeroAppOption.Instance.RequestSum})...");
            while (ZeroAppOption.Instance.RequestSum > 0)
            {
                cnt++;
                sec = (DateTime.Now - start).TotalSeconds;
                if (sec > ZeroAppOption.Instance.MaxCloseSecond)
                {
                    Logger.Error($"{cnt}. 已等待{sec:F2}秒,虽然剩余请求数还有{ZeroAppOption.Instance.RequestSum}),但已超过最大等待时间({ZeroAppOption.Instance.MaxCloseSecond}秒),系统将强行关闭。");
                    break;
                }
                Logger.Information($"{cnt}. 已等待{sec:F2}秒,剩余请求数:{ZeroAppOption.Instance.RequestSum}...");
                await Task.Delay(50);
            }
            sec = (int)(DateTime.Now - start).TotalSeconds;
            if (sec > 0)
            {
                Logger.Information($"{cnt}. 等待{sec:F2}秒后请求全部结束.");
            }
            Logger.Information("【正在退出...】");

            ZeroAppOption.Instance.SetApplicationState(StationState.Closing);
            await CloseAll();

            if (ZeroAppOption.Instance.ApplicationState != StationState.Closing)
            {
                return;
            }
            await WaitAllObjectSafeClose();

            ZeroAppOption.Instance.SetApplicationState(StationState.Closed);
            await DestoryAll();

            ZeroAppOption.Instance.SetApplicationState(StationState.Destroy);

            ScopeRuner.DisposeLocal();
            DependencyHelper.LoggerFactory.Dispose();


            Logger.Information("【已退出,下次见!】");
            if (ZeroAppOption.Instance.IsDevelopment)
            {
                Process.GetCurrentProcess().Kill();
            }
        }
Exemplo n.º 2
0
        async Task Hello2()
        {
            await Debug(2, context, GlobalContext.Current);

            context = GlobalContext.Current;
            await Task.Yield();

            await Task.Delay(100);

            await Debug(2, context, GlobalContext.Current);
            await Hello3();
            await Debug(2, context, GlobalContext.Current);

            ScopeRuner.DisposeLocal();
        }